【问题标题】:PHP Parsing Problem - and ÂPHP 解析问题 - 和
【发布时间】:2011-05-29 17:51:45
【问题描述】:
当我尝试解析一些带有  的html,然后echo 它,  “变成”这个字符:Â。此外,html_entity_decode() 和 str_replace() 不会改变它。
为什么会这样?如何删除 Â?
【问题讨论】:
标签:
php
html
parsing
character-encoding
【解决方案2】:
html_entity_decode(" ") == '\xa0'
我认为按照设计,我不明白为什么 str_replace 不适合你,试试这个 sn-p:
$nbsp = html_entity_decode(" ");
$s = html_entity_decode("[ ]");
$s = str_replace($nbsp, " ", $s);
echo $s;
也许 \xa0 它不是一个有效的 unicode 字符串,因此使用 html_entity_decode() 的结果可能更适合文本替换而不是 \xa0。
BalusC 的解释看起来很合理,您可能会尝试在其中插入 utf-8 \xc2\xa0 然后尝试将其显示为拉丁语而不是 utf8,如果您想使用 unicode 的东西,您应该在任何地方保留 utf-8 编码,从服务器的字符集到数据库,因为你在使用时会遇到同样的问题,例如à
【解决方案3】:
preg_replace() 也可以做到这一点:
preg_replace("/&#?[a-z0-9]{2,8};/i","", $var);