How does PHP read the content of a word document?

Source: Internet
Author: User
How does PHP read the content of a word document ;? Php // create an index pointing to the new COM component & nbsp; $ word = newCOM (& quot; word. application & quot;) ordie (& quot; Can 'tstartword! & Quot;); & nbsp; // display the method for reading the content of a word document using Wor PHP.
// Create an index pointing to the new COM component
$ Word = new COM ("word. application") or die ("Can't start Word! ");
// Display the version number of the Word currently in use
// Echo "Loading Word, v. {$ word-> Version}
";
// Set its visibility to 0 (false). If you want to enable it at the frontend, use 1 (true)
// To open the application in the forefront, use 1 (true)
// $ Word-> Visible = 0;
// Play? One document
$ Word-> Documents-> OPen ("E: \ wamp \ www \ oa \ 121.doc ");
// Read the document content
$ Test = $ word-> ActiveDocument-> content-> Text;
Echo $ test;
Echo"
";
// Replace the variable to be changed in the document
$ Test = str_replace ("<{variable}>", "This is a variable", $ test );
Echo $ test;
$ Word-> Documents-> Add ();
// Add text to the new document
$ Word-> Selection-> TypeText ("$ test ");
// Save the document in the directory
$ Word-> Documents [1]-> SaveAs ("E:/wamp/www/oa/121.doc ");
// Close the connection with COM components
$ Word-> Quit ();
?>
Error Report
Fatal error: Uncaught exception 'com _ exception' with message 'failed' to create com object' word. application ': too many characters § maid in E: \ wamp \ www \ oa \ newfile. php: 3 Stack trace: #0 E: \ wamp \ www \ oa \ newfile. php (3): com-> com ('Word. applicatio... ') #1 {main} thrown in E: \ wamp \ www \ oa \ newfile. php on line 3
I want to ask what a COM is !! Where
$ Test = str_replace ("<{variable}>", "This is a variable", $ test); how to write the variable here


------ Solution --------------------
COM is an information service component of Microsoft.

Your program runs on the condition that the word97 to word2003 versions have been installed on your server.
------ Solution --------------------
When I tried to convert PDF to WORD, I tried to write and write the word through PHP. it is slow. I suggest not doing it. I used WIN7 + APACHE + PHP + MYSQL, browser tested IE, 360, window of the world

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.