php 转 rtf, é变成é

发布于 2024-11-02 03:30:25 字数 796 浏览 7 评论 0原文

使用这个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浊酒尽余欢 2024-11-09 03:30:25

好吧,最后我用以下方法解决了它:

mb_convert_encoding($text,'ISO-8859-15','utf-8');

Well, finally I solved it using:

mb_convert_encoding($text,'ISO-8859-15','utf-8');
不必你懂 2024-11-09 03:30:25

你得到了双重编码。 \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.

浅浅 2024-11-09 03:30:25

您应该询问该脚本的作者,但从文档和提供的编码来看,它对 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.

把昨日还给我 2024-11-09 03:30:25

嗯,从 mysql 中提取时遇到同样的问题。我的页面采用 UTF-8 编码,我的数据库也是如此。我什至通过

if (!$mysqli->set_charset("utf8")) {echo "utf8 on";} else {echo "utf8 already on";}; 

不加任何帮助来强制 mysqli 进入 utf-8 模式,我不断得到 É

这是我的解决方案,不是雄辩的,但它有效。

echo str_replace('é', 'é', $mySQLResult);

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

if (!$mysqli->set_charset("utf8")) {echo "utf8 on";} else {echo "utf8 already on";}; 

nothing helps, i keep getting é

this was my solution, not eloquent, but it works.

echo str_replace('é', 'é', $mySQLResult);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文