Home >Backend Development >PHP Tutorial >Use PHP to generate word documents_PHP tutorial

Use PHP to generate word documents_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:27:46941browse

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="

 

Use php to create word documents

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:

利用php生成word文档  帮客之家

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/814687.htmlTechArticleUse 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.;...
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