Php converts html to word and doc

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.