请知悉:本文最近一次更新为 8年 前,文中内容可能已经过时。
function docx2text($filename) {
return readZippedXML($filename, "word/document.xml");
}
function readZippedXML($archiveFile, $dataFile) {
$zip = new ZipArchive;
if (true === $zip->open($archiveFile)) {
if (($index = $zip->locateName($dataFile)) !== false) {
$data = $zip->getFromIndex($index);
$zip->close();
$xml = new DOMDocument();
$xml->loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
$date=$xml->saveXML();
$date=str_replace("</w:p>","\r\n",$date);
return strip_tags($date);
}
$zip->close();
}
return "";
}

代码参考修改自:
https://webcheatsheet.com/PHP/reading_the_clean_text_from_docx_odt.php
https://stackoverflow.com/questions/22632086/error-in-domdocumentloadxml


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《PHP-读取docx文件纯文本》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌