Php output to the word garbled

Source: Internet
Author: User
& Quot; writeFile ($ path, $ data); write the buffer content into the w phpword garbled

 
   ';} Function save ($ path) {echo""; $ Data = ob_get_contents (); // return the content of the output buffer ob_end_clean (); // clear the buffer and disable the output buffer $ this-> writeFile ($ path, $ data); // write the buffer content to the word} function writeFile ($ fn, $ data) {$ fp = fopen ($ fn, "wb + "); fwrite ($ fp, $ data); fclose ($ fp) ;}}$ word = new Word (); $ word-> start (); // the following content will be saved in the WORD file. can I use HTML Tags?> Directly use php to create a word document by axgle
      

If you open data.doc and see the introduction here, the word document is created successfully.

In any operating system, you can use PHP to generate Word documents. It's definitely not a blow! A word file can be generated even if no word is installed. Of course, the generated word file can be opened with word, wps or other software.

Usage:
Use $ word-> start () to generate a word file. Then you can output any HTML code, whether it is read from the file and written here, or output HTML directly here.

After the output is complete, use the $ word-> save ($ path) method. $ path is the name of the word file you want to generate (the complete path can be provided ). when you use the $ word-> save () method, any output after this is irrelevant to the word file, that is, the word generation is complete. And then pull it in the same way as you normally use php. Anything you output is directly output in the browser instead of written into the word.

This is a very interesting method I have come up with. its implementation method is surprisingly simple, and it avoids dependency on the windows environment.
Haha, is it interesting? Enjoy it!

Save ("d:/wamp/www/up1/data.doc"); // save and end the word. // the following Content is normally output in the page file header ("Content-type: text/html; charset = utf-8"); echo 'data.doc is generated successfully, please go to the directory to view
';?>

This code can run, but I want to replace the text output in the html format Similar forms become garbled. how can this problem be solved?

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.