Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要制作一个 PHP 函数来计算 Word 文件(.doc、docx)中的行数
这段代码对我来说似乎无法正常工作:
$name = 'test.doc'; $line_count = count(file($name)); echo $line_count
我的猜测是该脚本不适用于 .doc 或 .docx,但适用于 .txt 文件。那里有替代品吗?天呐!
只能.docx用 simple 打开,PHP因为它是一个zip文件:
.docx
PHP
zip
$zip = new ZipArchive; if ($zip->open('test.docx') === TRUE) { $xml = $zip->getFromName('docProps/app.xml'); $zip->close(); } else { $xml = false; } if($xml){ $xml = simplexml_load_string($xml); echo $xml->Lines; }