Example of php converting word to html document

Source: Internet
Author: User
Word documents are not suitable for storing on webpages. if we want to put them in webpages, we need to copy them one by one. if you are still copying them, we will get out, the following is an example of converting word to html in php. I hope this article will be helpful to you. to be perfect... word documents are not suitable for storing on webpages. if we want to put them in webpages, we need to copy them one by one. if you are still copying them, we will get out, the following is an example of converting word to html in php. I hope this article will be helpful to you.

To solve this problem perfectly, it is best to convert office to pdf or html. libreoffice cannot be converted perfectly, and wps has no api.

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, 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.

Extension = php_com_dotnet.dll

Then restart and the code is as follows:

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.

Add an example:

function lego_clean($text) {               $text = implode("\r",$text);           // normalize white space        $text = eregi_replace("[[:space:]]+", " ", $text);        $text = str_replace("> <",">\r\r<",$text);        $text = str_replace("
","
\r",$text); // remove everything before $text = strstr($text," ]*BodyTextIndent[^>]*>([^\n|\n\015|\015\n]*)

","

\\1

",$text); $text = eregi_replace("

]*margin-left[^>]*>([^\n|\n\015|\015\n]*)

","
\\1
",$text); $text = str_replace(" ","",$text); //clean up whatever is left inside

and

  • $text = eregi_replace("

    ]*>","

    ",$text); $text = eregi_replace("

  • ]*>","
  • ",$text); // kill unwanted tags $text = eregi_replace(" ]*>","",$text); $text = eregi_replace(" ]*>","",$text); $text = eregi_replace(" ]*>","",$text); $text = eregi_replace("<\![^>]*>","",$text); $text = eregi_replace(" ]*>","",$text); // kill style and on mouse* tags $text = eregi_replace("([ \f\r\t\n\'\"])style=[^>]+", "\\1", $text); $text = eregi_replace("([ \f\r\t\n\'\"])on[a-z]+=[^>]+", "\\1", $text); //remove empty paragraphs $text = str_replace("

    ","",$text); //remove closing $text = str_replace("","",$text); //clean up white space again $text = eregi_replace("[[:space:]]+", " ", $text); $text = str_replace("> <",">\r\r<",$text); $text = str_replace("
    ","
    \r",$text); }

  • Article address:

    Reprint at will ^ please include the address of this article!

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.