Php export method to generate word, _ PHP Tutorial

Source: Internet
Author: User
Php export to generate the word method ,. Php export to generate the word method. this example describes how to export and generate the word in php. For your reference, please refer to the following details: export word in PHP (1) first, preview the html page, and export the method to generate word in php,

This example describes how to export and generate a word in php. We will share this with you for your reference. The details are as follows:

PHP export word

(1) first, preview the html page, sample object, and define the data to be exported.
(2) click the download page to pass a value to the id (any value can be used for determination only). if the id has a value, the output buffer file is saved as the word format.
(3) Click Download. (if an image is saved as a word, use the absolute path to display it normally in the saved word)
(4) Disable Cache output

Word_con.php preview the html file to be exported

<? Phpif (@ $ _ GET [id]! = '') {Include ('Word _ fun. php '); $ word = new word (); // sample object $ word-> start (); // define the start of the data to be saved} include ('Word _ show. php '); if (@ $ _ GET [id]! = '') {$ Word-> save('word_c.doc '); // defines the end of the data to be saved, at the same time, save the data to the word} if (@ $ _ GET [id] = '') {// The x in the hyperlink is only used to pass a value and confirm the download, no other actual yi?>

Click to jump to the download page

<? Php} else {echo "download" ;}?>

Word_fun.php export word-related functions

<? Phpclass word {function start () // defines the start of the data to be saved {ob_start (); // starts to output the buffer // sets the format of the generated word print'';} Function save ($ path) // defines the end of the data to be saved, and saves the data to word. // the data to be saved must be limited to start () of this class () and save () {print""; $ Data = ob_get_contents (); // return the internal buffer content to convert the output to the string ob_end_clean (); // end the output buffer, clean (erased) output Buffer and disable output buffer $ this-> wirtetoword ($ path, $ data);} function wirtetoword ($ fn, $ data) // save the data in binary format to word {$ fp = fopen ($ fn, "wb"); fwrite ($ fp, $ data ); fclose ($ fp) ;}}?>

Word_show.php connects to the database and queries related data

<? Php include ('Conn. php '); // connect to the database $ sq = "select zf_content from zf where 'zf _ id' = 137"; $ SQL = mysql_query ($ sq ); while ($ que = mysql_fetch_array ($ SQL ))! = False) {echo "hahaahahha"; echo $ que ['zf _ content'] ;}?>

I hope this article will help you with PHP programming.

Articles you may be interested in:
  • Simple sample code for exporting Word documents and excel workbooks using php
  • Php code example for exporting word format data
  • Principles and Examples of using PHP to export Word documents
  • PHP code for exporting webpages as word documents
  • How to use PHP to generate word documents in Windows
  • Php backup database code (generate word, excel, json, xml, SQL)
  • Php generates Word documents and provides the downloaded code in the program.

Examples in this article describes how to export and generate a word in php. Share it with you for your reference. The details are as follows: export word in PHP (1) first, preview the html page ,...

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.