php - utf-8转iso-8859-1编码问题

标签 php encoding utf-8 rss iso-8859-1

我正在尝试从另一个网站上的 RSS 提要预览最新的帖子。提要采用 UTF-8 编码,而网站采用 ISO-8859-1 编码。显示标题时,我正在使用;

 $post_title = 'Blogging – does it pay the bills?';

 echo mb_convert_encoding($post_title, 'iso-8859-1','utf-8');

 // returns: Blogging ? does it pay the bills?
 // expected: Blogging - does it pay the bills?

请注意,我期待的连字符不是普通的减号,而是一些大屁股的 super 破折号。好吧,无论如何要长几个像素。 :) 不确定如何描述它,因为我的键盘无法产生该字符...

最佳答案

mb_convert_encoding 仅转换内部编码 - 它实际上不会将字符的字节序列从一种字符集更改为另一种字符集。为此你需要 iconv .

mb_internal_encoding( 'UTF-8' );
ini_set( 'default_charset', 'ISO-8859-1' );

$post_title = 'Blogging — does it pay the bills?'; // I used the actual m-dash here to best mimic your scenario

echo iconv( 'UTF-8', 'ISO-8859-1//TRANSLIT', $post_title );

或者,正如其他人所说,只需将超出范围的字符转换为 html 实体。

关于php - utf-8转iso-8859-1编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1567100/

相关文章:

php - 没有原始文本弹出窗口的 Bing 翻译器小部件

php - 在Windows Server中安装phpmotion?

php - 使用 php 执行外部程序(如 skype.exe)

c# - 编码.UTF8 默认

Python UTF-8 小写土耳其语特定字母

java - OkHttp 和 UTF-8 字符编码

php - 如何使用 php 连接到所有类型的数据库?

ruby - Ruby 1.9.3 编码问题的 Mechanize

算法:按预期频率将符号压缩成位串?

java - 为什么 Eclipse 使用 Cp1252 编码?