PHP substr从xml feed中提供奇怪的字符

时间:2014-04-16 16:27:10

标签: php xml

出于某种原因,当使用substr时,我在输出上得到了一个奇怪的字符,就像这个“”。

我所做的就是:

$price = substr($game->price, 1);
$dollars_original = substr($game->fullPrice, 1);
echo "Price: $" . $price . "<br />\n";
echo "Original Price: $" . $dollars_original . "<br />\n";

这来自这里的XML提要:http://itch.io/browse/platform-linux/price-sale.xml,我这样解析:

$url = 'http://itch.io/browse/platform-linux/price-sale.xml';
$xml = simplexml_load_string(file_get_contents($url));

因此,例如价格可能是0.89英镑但是,当删除£符号时它出现为 0.89

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

看起来你在角色编码方面有混淆。什么是Latin-1或Windows-1252,什么是UTF-8?如果您正在处理UTF-8数据,则可能必须使用支持UTF-8的mb_substr()。