PHP moves HTML into Word

Source: Internet
Author: User

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

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.