This is tested, this method is a bit bad, HTML page code to write in PHP, but somehow can run, see the program
<?php
Class word{
function Start () {
Ob_start ();
Echo '
xmlns:w= "Urn:schemas-microsoft-com:office:word"
xmlns= "HTTP://WWW.W3.ORG/TR/REC-HTML40" > ";
}
function Save ($path)
{
echo "
$data = Ob_get_contents ();
}
function Wirtefile ($FN, $data) {
$FP =fopen ($fp, $data);
Fwrite ($fp, $data);
}
}
$html = '
<table width=600 cellpadding= "6" cellspacing= "1" style= "border:1px solid green;" style= "Border-collapse:collapse" >
<TR style= "border:1px solid green;" >
<TD style= "border:1px solid green;" > Name </td>
<TD style= "border:1px solid green;" > Sex </td>
<TD style= "border:1px solid green;" > Age </td>
<TD style= "border:1px solid green;" > Hobbies </td>
<TD style= "border:1px solid green;" > Notes </td>
</tr>
<TR style= "border:1px solid green;" >
<TD style= "border:1px solid green;" > Zhang San </td>
<TD style= "border:1px solid green;" > Men </td>
<TD style= "border:1px solid green;" >32</td>
<TD style= "border:1px solid green;" > Football </td>
<TD style= "border:1px solid green;" > No </td>
</tr>
<TR style= "border:1px solid green;" >
<TD style= "border:1px solid green;" >
John Doe
</td>
<TD style= "border:1px solid green;" > Male </TD><TD style= "border:1px solid green;" >43</TD><TD style= "border:1px solid green;" > Basketball </TD><TD style= "border:1px solid green;" > No </td>
</tr>
</table>
‘;
Batch Build
for ($i =1; $i <3; $i + +) {
$word = new Word ();
$word->start ();
$wordname = ' personal test php generated Word.doc ';
Echo $html;
$word->save ($wordname);
Header (' Content-type:application/word ');
Header (' content-disposition:attachment; Filename= '. $wordname. ');
ReadFile ($wordname);
Ob_flush ();//flush cache before each execution
Flush ();
//}
?>
This article is from the IT-related technology blog, so be sure to keep this source http://luofeng868.blog.51cto.com/3974480/1737908
PHP moves HTML into Word