Examples: how to convert html word in PHP
The following code describes how php transfers html to word. The specific content is as follows:
This is tested. This method is not good. The html page code should be written in php, but it can be run and viewed by the program.
<? Php class word {function start () {ob_start (); echo '
Below is a piece of code for php to convert word to html.
To solve this problem perfectly, we 'd better use windows office software to convert office to pdf or html. libreoffice cannot be converted perfectly, and wps has no APIs.
Check whether the com module is enabled. If there is a com_dotnet module in phpinfo, it indicates that it is enabled. If not, modify php. ini,
The Code is as follows:
Com. allow_dcom = true
The comment above is removed, and the restart will be OK. The official php website said that the com module was built in before php5.4.5, but not necessarily all. The official website's php 5.3.39, the com module is not built in.
If it is not a built-in module, add it to php. ini, provided that the extension is available in your ext folder.
The Code is as follows:
extension=php_com_dotnet.dll
Then restart the instance.
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. The converted html is messy to view the source code.
2. winword.exe will be used in the conversion process
3. If the page is being loaded, rename the document and re-convert it.
Articles you may be interested in:
- Php implements the method of converting uploaded word files to html
- Use of PHP functions related to HTML and filtering links in WordPress
- Php to convert word to html