php 转 rtf, é变成é
使用这个 rtf 类,我看到我的特殊字符被转换,比如 é 变成 \ 'C3\'A9
(该部分可能不是问题)
一旦我使用 php 标头将其放入 rtf 中,生成的字符 (é) 将被视为 é
。
header("Content-type: application/rtf; charset=utf-8");
header("Content-Disposition: attachment; filename=$file_rtf");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
奇怪的!我的文件以 utf-8 保存,仅供参考。
我在获取 excel 时遇到了类似的问题,但使用 This is not work for rtf 解决了这个问题
$text = mb_convert_encoding($text,'utf-16','utf-8');
。感谢您的任何帮助。
附言。我的文件通过DW使用utf-8编码保存,我的mysql默认字符集也是utf-8。当我直接从数据库显示字符时没有问题,但只有当我在使用标题之前直接在页面中键入特殊字符时才会出现此问题。
干杯。
Using this rtf class, I see my special characters getting converted, like é becomes \'C3\'A9
(that part is probably not the problem)
Once I get it in rtf using php header, the resulting character (é) is seen as é
.
header("Content-type: application/rtf; charset=utf-8");
header("Content-Disposition: attachment; filename=$file_rtf");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
Strange! My file is saved in utf-8, for information.
I had a similar problem while getting excel, but that is solved using
$text = mb_convert_encoding($text,'utf-16','utf-8');
This is not working for rtf. Thanks for any help.
PS. My file is saved with utf-8 encoding thro' DW, and my mysql default charset is also utf-8. I don't have a problem when I display a character directly from the database, but this problem is seen only when I type a special character directly into the page before to use the header.
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,最后我用以下方法解决了它:
Well, finally I solved it using:
你得到了双重编码。
\N{LATIN SMALL LETTER E WITH ACUTE}
字符是代码点 U+00E9。在 UTF-8 中,即\xC3\xA9
。但是,如果您转身并将这两个字节视为不同的代码点 U+00C3 和 U+00A9,则它们是
\N{LATIN CAPITAL LETTER A WITH TILDE}
和\N{COPYRIGHT SIGN }
分别。现在,一旦那些依次重新编码,您就得到了字节序列
\xC3\x83\xC2\xA9
,这就是您想要的正在看到。你是Windows系统吗?他们似乎经常对事物进行双重重新编码。
You’re getting double-encoded. A
\N{LATIN SMALL LETTER E WITH ACUTE}
character is code point U+00E9. In UTF-8, that is\xC3\xA9
.But if you turn around and treat those two bytes as distinct code points U+00C3 and U+00A9, those are
\N{LATIN CAPITAL LETTER A WITH TILDE}
and\N{COPYRIGHT SIGN}
, respectively.Now once those now in turn get re-encoded, you get the byte sequence
\xC3\x83\xC2\xA9
, which is what you are seeing.Are you on Windows system? They often seem to double-re-encode things.
您应该询问该脚本的作者,但从文档和提供的编码来看,它对 UTF8 不友好。因此,您可以尝试将文本转换为代码页(例如 cp1251)并使用此类中的可用编码之一来找到最佳结果。
You should ask author of the script, but judging from documentation and provided encodings, it is not UTF8 friendly. So you may try converting text to your code page (ex. cp1251) and using one of available encodings in this class to find best results.
嗯,从 mysql 中提取时遇到同样的问题。我的页面采用 UTF-8 编码,我的数据库也是如此。我什至通过
不加任何帮助来强制 mysqli 进入 utf-8 模式,我不断得到 É
这是我的解决方案,不是雄辩的,但它有效。
hmm, having the same problem pulling from mysql. My page is encoded in UTF-8, as is my database. I'm even forcing mysqli into utf-8 mode by putting
nothing helps, i keep getting é
this was my solution, not eloquent, but it works.