Home  >  Article  >  Backend Development  >  Generate word document with php_PHP tutorial

Generate word document with php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:31:161061browse

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='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">'.$data.'</html>';
	if(empty($fileName)) $fileName=date('YmdHis').'.doc';
	$fp=fopen($fileName,'wb');
	fwrite($fp,$data);
	fclose($fp);
}

Examples are as follows:

<?php $str='<title>利用php创建word文档
 <h1>利用php创建word文档</h1>
 作者:phpernote.com
<hr size="1">
 <p>如果你打开word.doc,看到了这里的介绍,则说明word文档创建成功了。</p>
<p>
<b>版权所有:</b>
<br>www.phpernote.com
</p><hr size="1">';
word($str);

Rendering:

Generate word document with php_PHP tutorial

Articles you may be interested in

  • The idea and implementation method of generating short URLs in PHP
  • Several methods of generating random numbers in PHP
  • PHP generates a random password function
  • A summary of the method of generating a random password in php
  • How to generate an image thumbnail in php
  • How to generate a QR code in php Summary
  • Examples of PHP generating download links for Thunder, Express and QQ Tornado
  • PHP generating verification code function

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764098.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='html x...
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