PHP Export method for generating word, _php tutorial

Source: Internet
Author: User

PHP exports the method that generates word,


The example in this article describes how PHP exports generate word. Share to everyone for your reference, as follows:

PHP Export Word

(1) First, preview the HTML page, instantiate the object, define the data to be exported
(2) Click on the download page, give the ID value (any value can be used only to determine), if the ID has a value, output buffer file, saved in Word format.
(3) After clicking on the download, (if it is a picture, use absolute path when saving as word, so that it can be displayed normally in saved word)
(4) Turn off cache output

word_con.php previewing the HTML file to export

<?phpif (@$_get[id]!= ") {include (' word_fun.php '); $word =new Word ();//Sample Object $word->start ();//define the beginning of the data to be saved} Include (' word_show.php '); if (@$_get[id]!= ') {   $word->save (' Word_c.doc ');//define the end of the data to be saved and save the data to Word} if (@$_get[id]== ") {// The x in the hyperlink is simply to pass a value, confirm the download, no other actual Yi?> Click to jump to the download page <?php}else{echo "Download";}? >

word_fun.php exporting Word related functions

<?phpclass word{function Start ()//define the beginning of the data to be saved {    ob_start ();//Start output buffer    //set to generate Word format    print ';} function Save ($path)//define the end of the data to be saved, while saving the data in Word  //The data to be saved must be limited to the class's start () and save () {print "; $data =ob_get_ Contents (); Returns the contents of the internal buffer to turn the output into a string Ob_end_clean (); End output buffer, clean (erase) output buffer and turn off output buffer $this->wirtetoword ($path, $data);} function Wirtetoword ($FN, $data)//Save the data in binary form to Word {$fp =fopen ($FN, "WB"), Fwrite ($fp, $data); fclose ($FP);}}? >

word_show.php connection database, query related data

<?php  include (' conn.php ');//Connect 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 is helpful to you in PHP programming.

Articles you may be interested in:

    • Simple sample code for PHP to export Word documents and Excel spreadsheets
    • code Example of PHP exporting Word format data
    • Principles and examples for exporting Word documents using PHP
    • Code for exporting a Web page as a Word document in PHP
    • Tutorials for using PHP to generate Word documents under Windows systems
    • PHP Backup Database code (generate Word,excel,json,xml,sql)
    • PHP generates a Word document in the program and provides the downloaded code

http://www.bkjia.com/PHPjc/1084535.html www.bkjia.com true http://www.bkjia.com/PHPjc/1084535.html techarticle PHP exports the way to generate word, this article describes the way PHP exports to generate word. Share to everyone for reference, as follows: PHP export Word (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.