Home >Backend Development >PHP Tutorial >Directly use PHP to create word document code (no need to install word software on the system)_PHP tutorial

Directly use PHP to create word document code (no need to install word software on the system)_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:08:191059browse

Directly use PHP to create word document code (the system does not need to install word software). How to use: First, use $word->start() to indicate that a word file is to be generated. Then you can output any HTML code, whether you read it from the file and write it here, or output the HTML directly here, it doesn't matter.

Directly use the PHP tutorial to create the word document code (the system does not need to install word software)
Usage:
First use $word->start() to indicate that the word file is to be generated. Then you can output any html code, whether you read it from the file and write it here, or output html directly here, it doesn't matter.
After you finish outputting, use the $word->save($path) method, where $path is the name of the word file you want to generate (the complete path can be given). When you use $word- >After the save() method, any subsequent output has nothing to do with the word file, which means that the word generation work is completed. Then just pull it the same way you normally use php. Whatever you output will be output directly in the browser and will not be written into Word.

*/

class word
{

function start()
{
ob_start();
print'< ;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">';

}

function save($path)
{

print "$data = ob_get_contents();

ob_end_clean();

$this->wirtefile ($path,$data);
}

function wirtefile ($fn,$data)
{

$fp=fopen($fn,"wb");
fwrite($fp,$data);
fclose($fp);
}

}
//Generate word calling method
include("word.php");
$word=new word;
$word->start();


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444887.htmlTechArticleUse PHP directly to create word document code (the system does not need to install word software) How to use: First use $word->start () indicates that a word file is to be generated. Then you can output any HTML code, no matter...
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