Home >Backend Development >PHP Problem >How to convert word to html in php
php method to convert word to html: 1. Use the editor to open the php.ini configuration file; 2. Find [com.allow_dcom = true] and uncomment it; 3. Restart the server; 4. Convert word Just convert it to html.
To solve this problem perfectly, it is best to use windows office software to convert office to pdf or html. Libreoffice cannot convert perfectly, and wps does not have an API.
(Learning video recommendation: java video tutorial)
First confirm whether the com module is turned on. If there is a com_dotnet module in phpinfo, it means it is turned on. If If not, modify the PHP.ini file, unconfigure the comment com.allow_dcom = true and restart.
The official website of php says that before php5.4.5, the com module was built-in, but in fact it may not always be the case. In php 5.3.39 under the official website, the com module is not built-in.
If it is not a built-in module, add it to php.ini. If you have the extension extension=php_com_dotnet.dll in your ext folder, then restart and it will be OK.
function word2html($wordname,$htmlname) { $word = new COM("word.application") or die("Unable to instanciate Word"); $word->Visible = 1; $word->Documents->Open($wordname); $word->Documents[1]->SaveAs($htmlname,8); $word->Quit(); $word = null; unset($word); } word2html('D:/www/test/6.docx','D:/www/test/6.html');
Note:
1. Check the source code of the converted html, it is quite messy
2. Winword.exe
will be called during the conversion process3. If the page keeps loading, rename the document and then load it again.
Related recommendations: php training
The above is the detailed content of How to convert word to html in php. For more information, please follow other related articles on the PHP Chinese website!