您将如何阅读 PHP 中的 odt 文件?我知道您可以使用 QueryPath,但这似乎有点矫枉过正,.. 我只想阅读该文件。
问问题
7613 次
4 回答
5
odt, files are zip compressed xml.
If all you need to do is read the file raw. Just unzip it and read it like a normal file.
If you need to parse out usable text, then enters the need for QueryPath or some other xslt parser.
于 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 回答