How to convert .docx file into .doc file with PHP?

时间:2015-06-26 09:29:55

标签: php docx doc phpword

I want to read the text from a .docx file line by line and keep the each line data in an array, since .docx is a zipped file i want to convert it into a .doc file so that I can read the file using @fopen($filename, 'r');.

Below is the code I tried using PHPWord to conver from .docx to .doc ,

<?php
require_once 'phpWord/PHPWord.php';

$PHPWord = new PHPWord();

$document = $PHPWord->loadTemplate('BasicTable.docx');

// Save File

$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');

$objWriter->save('BasicTable4.doc');
?>

and this creates an erroneous .doc file.

2 个答案:

答案 0 :(得分:0)

You can try to use PHPWord. ( http://phpword.codeplex.com/ )

It supports docx as well as doc.

答案 1 :(得分:0)

如果您想从.docx文件中获取文本并将其另存为文本文件,则可以使用库 docx2text

将其转换为文本文件后,您可以逐行读取文本文件,并将每个行数据保存在一个数组中。