PHP Action: Saves the data in the database to Word.

Source: Internet
Author: User

1. First defines a word class

<?phpclass word{function Start () {Ob_start ();    ob_start- Open output control buffer  }     function Save ($path) {$data = Ob_get_contents ();             ob_get_contents- Returns the contents of the output buffer  Ob_end_clean ();     ob_end_clean- empties (erases) the buffer and closes the output buffer  $this->wirtetoword ($path, $data);  } function Wirtetoword ($FN, $data) {$fp =fopen ($FN, "w");        fopen- Open a file or URL, the second parameter is how to open  fwrite ($fp, $data);      fwrite- Write file (can be used safely for binary files)  fclose ($FP); fclose- Close an open file pointer  }}?>

2. Refer to the class and invoke the data from the nation table from the database

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8" />    <title>Document</title></Head><Body>    <?php if (!isset ($_get["id")) {?>            <inputtype= "button"name= "Submit"value= "Save table contents to Word"onclick= "window.location.href= ' main.php?id=print '">        <?php}?>    <?php if ($_get["id"]!= "") {include ("word.class.php");   Reference the Word class in $word =new Word ();      Instantiate the class $word->start (); Call the Start () method to define the beginning of the table to save}?>                <TableBorder= "1"cellspacing= "0"cellpadding= "0">            <TR><th>Code</th><th>Name</th></TR>            <?php include ("..                /gongju/dbda.class.php ");                $db =new Dbda ();                $sql = "SELECT * From Nation";                $attr = $db->query ($sql); foreach ($attr as $v) {echo "<tr><td>{$v [0]}</td><td>{$v [1]}<                /td></tr> "; }                                ?>        </Table>        <?php if ($_get["id"]!= "") {$word->save ("Data.doc"); Save Table End}?>                    </Body></HTML>

PHP Action: Saves the data in the database to Word.

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.