: This article mainly introduces php implementation to convert html to word and doc. if you are interested in PHP tutorials, please refer to it.
$title
=
"PHP generate doc file"
;
$html
= 'Php generates doc files-old blog
Php generates doc formatWord documentsIt is relatively simple, mainly because it is easy to create an error when creating a Chinese name File. you can use iconv to convert the file before creation.
Php generates doc formatWord documentsIt is relatively simple, mainly because it is easy to create an error when creating a Chinese name File. you can use iconv to convert the file before creation.
The usage method is relatively simple, just output it directly:
echo
cword(
$data
, filename)
The usage method is relatively simple, just output it directly:
echo
cword(
$data
, filename)
This program"http://www.lao8.org"
> The old blog provides:
';
// Usage -------------------------
echo
(cword(
$html
,iconv(
"UTF-8"
,
"GB2312//IGNORE"
,
$title
); // Convert Chinese characters and ignore errors
//----------------------------------------
function
cword(
$data
,
$fileName
=
''
)
{
if
(
empty
(
$data
))
return
''
;
$data
=
''
.
$data
.
''
;
$dir
=
"./docfile/"
.
date
(
"Ymd"
).
"/"
;
if
(!
file_exists
(
$dir
))
mkdir
(
$dir
,777,true);
if
(
empty
(
$fileName
))
{
$fileName
=
$dir
.
date
(
'His'
).
'.doc'
;
}
else
{
$fileName
=
$dir
.
$fileName
.
'.doc'
;
}
$writefile
=
fopen
(
$fileName
,
'wb'
)
or
die
(
"An error occurred while creating the file"
);
// Wb is written in binary format
fwrite(
$writefile
,
$data
);
fclose(
$writefile
);
return
$fileName
;
}
The above introduces the php implementation of converting html to word, doc, including word documents, GB2312 content, hope to be helpful to friends interested in PHP tutorials.