php将html导出到word上

 public function downloadWord($content, $fileName='new_file.doc'){


        header("Cache-Control: no-cache, must-revalidate");
        header("Pragma: no-cache");
        header("Content-Type: application/octet-stream");
        
// 针对ie浏览器
if (preg_match ( "/Triden/", $ua )) {
    //$fileName  = iconv("utf-8","gb2312",$fileName);
    $fileName = iconv("utf-8","gb2312//IGNORE",$fileName);
    header ( "Content-Disposition: attachment; filename=".$fileName);
}else if (preg_match ( "/Firefox/", $ua )){
    header ( "Content-Disposition: attachment; filename*=\"utf8''" . $fileName . '"' );
}else{
    header ( "Content-Disposition: attachment; filename=".$fileName);
}
        header("Content-Disposition: attachment; filename=$fileName");

        $html = '';
        $html .= '';

        echo $html . ''.$content .'';
        // !important 强制样式 

    }

    public function TestDownloadWord(){

        $str = '

11月17日至19日,海南休闲旅游博览会在海口举办,中国老年大学协会教育成果在博览会上精彩亮相,协会独创的“游学养”老年教育新模式得到参会者一直好评。期间,中国老年大学协会游学管理中心主任陶定宏参加了中国休闲旅游推广联盟成立大会暨中国休闲旅游发展论坛并发言。



博览会现场

参会者领取老年教育宣传资料


中国老年大学协会游学管理中心主任陶定宏参加中国休闲旅游发展论坛


陶定宏在论坛上发言

陶定宏接受腾讯新闻采访


我也是他




'; $this->downloadWord($str, 'abc.doc'); }

你可能感兴趣的:(php将html导出到word上)