作者Clessin (Clemond)
看板PHP
标题Re: [请益] PHP 产生 RTF
时间Mon May 28 13:08:29 2012
※ 引述《a613204 (胖胖)》之铭言:
: header('Content-type: application/msword;charset=utf-8');
: header('Content-Disposition: inline, filename=app_form.rtf');
: $filename='app.rtf';
: $fp=fopen($filename,'r');
: $output=fread($fp, filesize($filename));
: fclose($fp);
: $output=str_replace('<<last_name>>',' '.$row->last_name,$output);
: $output=str_replace('<<first_name>>',' '.$row->first_name,$output);
: echo $output;
: 目前大概是以这种方式产生RTF档案
: 不过发现如果变数内容是中文的话会变成乱码
: 请问该怎麽处理呢?? 页面编码已经设定成utf8了
我也发生同样的问题!若用UTF-8编码的中文取代rtf档里面的变数,使用者下载回来
的档案会发生档案损毁,无法开档.我後来用iconv()来将UTF-8的中文字转成BIG5码
就可以了.但有些UTF-8的字转成BIG5会变乱码,目前这方面我也是无解.
我的作法如下:
<?php
$Output = file_get_contents("abc.rtf");
$Output = str_replace("<<first_name>>", iconv("utf-8","big5",$row->first_name),
$Output );
$Output = str_replace( "<<last_name>>", iconv("utf-8","big5",$row->last_name),
$Output);
header('Content-type:application/msword;charset=utf-8');
header('Content-Disposition: attachment;filename=abc.doc');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_clean();
flush();
echo $Output;
exit;
?>
希望能抛砖引玉,有那位大大可以指导一下,怎样才能原汁原味不用将UTF-8
编码的中文直接取代rtf档内的变数符号,而不会发生档案损毁,无法开档的错误.
请指导,谢谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.72.181.22
2F:→ Clessin:回楼上的大大,刚试过了,没用.还是档案无法开启.谢谢! 05/28 14:24