PHP Tutorial example: Use a PHP script to bring your own word document program

Source: Internet
Author: User
PHP native word document code, which is used to produce the simple PHP code of the exam // contains the database connection file and header file

// Initialize the session
Session_start ();
// Contains the database connection file and header file
?>
 
 
Exam native 
 
 
Include ('head. php ');
Require ('dbconnect. php ');
?>
$ Juge = 0;
For ($ I = 1; ($ I <100); $ I)
{
$ A = $ I;
If (isset ($ _ POST [$ a])
{
If ($ juge = 0)
$ SQL. = 'Id = '. $ _ POST [$ a];
Else
$ SQL. = 'or id ='. $ _ POST [$ a];
$ Juge = 1;
}
}
If ($ SQL! = '')
{
$ SQL = 'select * FROM test where'. $ SQL;
$ Result_array = array (); // returns an array.
$ I = 0; // array subscript
$ Query_result = @ mysql_query ($ SQL, $ conn );
While ($ row = @ mysql_fetch_object ($ query_result ))
{
$ I;
$ Cout. = $ I .'';
$ Cout. = 'title difficulty: '. $ row-> difficulty .'
';
$ Cout. = ''. $ row-> content .'

';
} // While

?>
Class word
{
Function start ()
{
Ob_start ();
Print'Xmlns: w = 'urn: schemas-microsoft-com: office: word'
Xmlns = '''> http://www.w3.org/TR/REC-html40'> ';
}

Function save ($ path)
{

Print'';
$ Data = ob_get_contents ();

Ob_end_clean ();
$ This-> wirtefile ($ path, $ data );
}
Function wirtefile ($ fn, $ data)
{
$ Fp = fopen ($ fn, 'WB ');
Fwrite ($ fp, $ data );
Fclose ($ fp );
}
}
/* ------- Word class End -------*/
$ Word = new word;
$ Word-> start ();
Echo $ cout;
$ Wordname = 'word/'.time().'.doc ';
$ Word-> save ($ wordname); // retain and end the word.
?>
'Target = _ blank class = 'unnamed1'> The test has been created. Click here to view details.
}
Else
{
?>
 
You are not allowed to enter. please enter again!
}
?>
 

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.