PHP Tutorial Example: A program to generate Word documents with PHP scripts

Source: Internet
Author: User
Tags array php code php tutorial xmlns

PHP generates the code for the Word document, which is a simple PHP code to produce the quiz paper

<?php
Initializing session
Session_Start ();
Contains database connection files and header files
?>
<title> Test paper Generation </title>
<link href= "Css/style.css" rel= "stylesheet" type= "Text/css" >
?
Include (' head.php ');
Require (' dbconnect.php ');
?>
? 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 (); Return array
$i = 0; Array subscript
$query _result= @mysql_query ($sql, $conn);
while ($row = @mysql_fetch_object ($query _result))
{
$i + +;
$cout. = $i. "";
$cout. = "Problem Difficulty:". $row->difficulty. " <br> ";
$cout. = "". $row->content. <br><br> ";
}//while

?>
<?php
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);//save Word and end.
?>
<div align= "center" ><a href= "<?php echo $wordname?>" Target=_blank class= "unnamed1" > Quiz paper has been generated, Please click here to view </a>
? Php
}
Else
{
?>
</div>
<div align= "center" ><span class= "unnamed1" > You have not entered enough conditions, please re-enter! </span>
? Php
}
?>
</div>



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.