Home > Backend Development > PHP Tutorial > PHP realizes converting html to word and doc

PHP realizes converting html to word and doc

WBOY
Release: 2016-07-29 09:12:00
Original
2196 people have browsed it

$title = "PHP generates doc file";

$html = '<h1>PHP generates doc files - Laoba Blog</h1>

<p>PHP generates <strong>word documents</strong> in doc format is relatively simple, The main thing is to note that it is easy to make mistakes when creating files with Chinese names. Just use iconv to convert them before creation. The main thing is to note that it is easy to make mistakes when creating files with Chinese names. Just use iconv to convert them before creating them.</p>

<p>The usage method is relatively simple. Just output it directly: <strong></strong>echo

cword(

$data, filename) </p><p>The method of use is relatively simple, Just output it directly: echo

cword(

$data, filename) </p><p>This program is written by<a href="http://www.lao8.org"

>Laoba BlogProvided by:

';

//How to use-------------------------

echo

(cword(

$html

,iconv(

"UTF-8"

,

"GB2312//IGNORE",$title))); //Convert to Chinese and ignore errors//------------------------------------- ---<strong></strong>function

cword(

$data

,

$fileName

=

'') {​​​if (

empty

(

$data

)) return ''; $ data=

''

.

$data

.'</html>';                                                                                                . ". date( "Ymd"

).

"/"; file_exists($dir ))mkdir($dir,777,true);

($fileName)) { ).'.doc';

}

else {

$dir

.$fileName

.

'.doc' ; } fileName,'wb'

)

or die

(

"Failed to create file");

//wb is written in binary

fwrite(

$writefile,$data); fclose($writefile);

The above has introduced the PHP implementation of converting HTML to word and doc, including word documents and GB2312 content. I hope it will be helpful to friends who are interested in PHP tutorials. <p> </p>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template