: This article describes how to export and generate a word in php. For more information about PHP tutorials, see. 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?><? 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.
The above describes how to export and generate a word in php, including the relevant content. I hope my friends who are interested in the PHP Tutorial can help me.