php 批量生成 html转word

function cword($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"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><xml><w:WordDocument><w:View>Print</w:View></xml></head>'.$data.'</html>';
        $dir   = "E:/project" .__ROOT__.'/ask/';
        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("创建文件失败");//wb以二进制写入
        fwrite($writefile,$data);
        fclose($writefile);
        return $fileName;
    }
 <xml><w:WordDocument><w:View>Print</w:View></xml>

猜你喜欢

转载自blog.csdn.net/lemqs0123/article/details/53284473