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

PHP realizes converting html to word and doc

WBOY
WBOYOriginal
2016-07-29 09:12:002173browse

$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>

Statement:
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
Previous article:laravel 5 用户管理Next article:laravel 表单验让