字符编码UTF8在PHP中使用mb_detect_encoding()时出现问题 [英] Character Encoding UTF8 Issue when using mb_detect_encoding() with PHP

查看:856
本文介绍了字符编码UTF8在PHP中使用mb_detect_encoding()时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读rss资讯提供 http://beersandbeans.com/feed/

I am reading an rss feed http://beersandbeans.com/feed/

它是UTF8格式,我使用simplepie rss导入内容当我抓取内容并将其存储在 $ content 我执行以下操作:

The feeds says it is UTF8 format, and I am using simplepie rss to import the content When i grab the content and store it in $content I perform the following:

<?php
header ('Content-type: text/html; charset=utf-8');
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head><body>
<?php
echo $content;
echo $enc = mb_detect_encoding($content, "UTF-8,ISO-8859-1", true);
echo $content = mb_convert_encoding($content, "UTF-8", $enc);
echo $enc = mb_detect_encoding($content, "UTF-8,ISO-8859-1", true);
?>
</body></html>

然后生成:

..... Camping:     2,000isk/day for 5 days) = $89 .....
ISO-8859-1
..... Camping: Â  Â           2,000isk/day for 5 days) = $89 .....
UTF-8

为什么要输出?

推荐答案

不要指定UTF- -8859-1,看看它给了你什么编码。它可能是检测ISO-8859-1,因为它是该列表中的最后一个,而不是字符串的实际编码。

Try not specifying "UTF-8,ISO-8859-1" and see what encoding it gives you. It might be detecting ISO-8859-1 because it's the last one in that list, rather than the actual encoding of the string.

这篇关于字符编码UTF8在PHP中使用mb_detect_encoding()时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆