您将如何阅读PHP中的ODT文件?我知道您可以使用Querypath,但这似乎有点过分,..我只想阅读该文件。

有帮助吗?

解决方案

ODT,文件为ZIP压缩XML。

如果您需要做的就是阅读文件。只需解压缩并像普通文件一样阅读。

如果您需要解析可用的文本,则输入需要Querypath或其他一些XSLT解析器。

其他提示

OPENTBS 能够在PHP中读取和修改Opentocument文件。

由于Opentocument文件是存储在zip存档中的XML文件,您也可以使用 tbszip 课堂只需在PHP下读取邮政编码,而无需任何其他库依赖。

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top