PHPでodtファイルをどのように読みますか?QueryPathを使用できることは知っていますが、それは少しやり過ぎのようです。ファイルを読みたいだけです。
7613 次
4 に答える
5
odt、ファイルはzip圧縮されたxmlです。
あなたがする必要があるのはファイルを生で読むことだけです。解凍して通常のファイルのように読んでください。
使用可能なテキストを解析する必要がある場合は、QueryPathまたはその他のxsltパーサーの必要性を入力します。
于 2010-11-01T15:13:52.663 に答える
1
/*Name of the document file*/
$document = 'Template.odt';
/**Function to extract text*/
function extracttext($filename) {
$dataFile = "content.xml";
//Create a new ZIP archive object
$zip = new ZipArchive;
// Open the archive file
if (true === $zip->open($filename)) {
// If successful, search for the data file in the archive
if (($index = $zip->locateName($dataFile)) !== false) {
// Index found! Now read it to a string
$text = $zip->getFromIndex($index);
// Load XML from a string
// Ignore errors and warnings
$xml = new DOMDocument;
$xml->loadXML($text, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
// Return XML
return $xml->saveXML();
}
//Close the archive file
$zip->close();
}
// In case of failure return a message
return "File no`enter code here`t found";
}
echo extracttext($document);
于 2019-02-24T14:55:30.737 に答える
0
http://pear.php.net/package/OpenDocumentが必要な場合があります。ただし、自分で使用したことはありません。
于 2011-03-07T12:30:32.310 に答える