سؤال
كيف يمكنك قراءة ملفات ODT في PHP؟ أعلم أنه يمكنك استخدام QueryPath ، لكن هذا يبدو قليلاً من المبالغة ، .. أريد فقط قراءة الملف.
المحلول
ODT ، الملفات هي مضغوطة مضغوطة.
إذا كان كل ما عليك فعله هو قراءة الملف الخام. فقط قم بفك ضغطه وقراءته مثل ملف عادي.
إذا كنت بحاجة إلى تحليل النص القابل للاستخدام ، فإنه يدخل الحاجة إلى QueryPath أو بعض محلل XSLT الآخر.
نصائح أخرى
http://pear.php.net/package/opendocument قد يكون ما تحتاجه. لم أستخدمها بنفسي.
/*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);
لا تنتمي إلى StackOverflow