la lettura dei file odt in php
-
28-09-2019 - |
Domanda
Come si va sulla lettura dei file odt in PHP? So che è possibile utilizzare percorso query, ma che sembra un po 'di un peso inutile, .. voglio solo leggere il file.
Soluzione
xml odt, i file vengono compresso.
Se tutto quello che dovete fare è leggere il file raw. Basta decomprimere e leggerlo come un normale file.
Se avete bisogno di analizzare fuori di testo utilizzabile, poi entra la necessità di percorso query o qualche altro parser XSLT.
Altri suggerimenti
http://pear.php.net/package/OpenDocument può essere quello che ti serve . Non hanno usato io stesso, però.
/*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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow