我现在正在做一个项目,而且我一直在阅读word文档.
- This is a test word file in PHP.
- Thank you.
- $myFile = "wordfile.docx";
- $fh = fopen($myFile,'r');
- $theData = fread($fh,1000);
- fclose($fh);
- echo $theData;
输出:
- PK!éQ°Â[Content_Types].xml ¢( ´”MOÂ@†ï&þ‡f¯¦]ð`Œ¡pP<*‰Ïëv
- «Ýì,_ÿÞiI¡(ziÒNß÷}fÚÞ`©‹h•5)ë&‘6Sf’²×ñc|Ë"Âd¢°R¶dƒþåEo
- ¼r€© ¦l‚»ãå´ÀÄ:0TÉ×"Пp'䧘¿îtn¸´&€ q(=X¿÷¹˜!.éñ
- š„ä,º_¿WF¥L8W()ò²Êu <"œ›l.Þ%¤¬Ìqª^Nøp0ÙKPºl*Õ3Ó
- «¢‘ðáIhbçë3žY9ÓÔwr¼¹F›çJB/Ýœ·é;é"©+Z(³e?ÈaUþ=ÅÚ÷Ä
- ø7¦Ã<I?Hû<4ÆeÓÉ:bGÛž!ÐN ùþÛÆmCÇs+ÂÞ_þbǼ$§ó4ïœ
- 0ñ£¶n…´#€W×îٕͱH:#oÒÎñ¿h{»JuLGÎ êõÐtÄêDZXg÷åFÌ kÈæÕîÿÿPK
- !ÇÂ'¼ß_rel
无论如何在那里读取PHP中的word文档?
对于docx使用此功能
- function read_docx($filename){
- $striped_content = '';
- $content = '';
- if(!$filename || !file_exists($filename)) return false;
- $zip = zip_open($filename);
- if (!$zip || is_numeric($zip)) return false;
- while ($zip_entry = zip_read($zip)) {
- if (zip_entry_open($zip,$zip_entry) == FALSE) continue;
- if (zip_entry_name($zip_entry) != "word/document.xml") continue;
- $content .= zip_entry_read($zip_entry,zip_entry_filesize($zip_entry));
- zip_entry_close($zip_entry);
- }
- zip_close($zip);
- $content = str_replace('</w:r></w:p></w:tc><w:tc>'," ",$content);
- $content = str_replace('</w:r></w:p>',"\r\n",$content);
- $striped_content = strip_tags($content);
- return $striped_content;
- }
它将从docx返回文本