Home >Backend Development >PHP Tutorial >Use PHP to generate word documents_PHP tutorial
Use PHP to generate word documents. The generated word files can be opened with word, wps and other software. The specific code is as follows:
Function word($data,$fileName=""){
if(empty($data)) return "";
$data="".$data."";
if(empty($fileName)) $fileName=date("YmdHis").".doc";
$fp=fopen($fileName,"wb");
fwrite($fp,$data);
fclose($fp);
}
Examples are as follows:
$str="
Author: Alixixi.com
If you open word.doc and see the introduction here, it means that the word document has been created successfully.
Copyright:
www.Alixixi.com
";
word($str);
Rendering: