【发布时间】:2014-02-15 09:21:08
【问题描述】:
function decode_entities($text) {
$text= html_entity_decode($text,ENT_QUOTES,"ISO-8859-1"); #NOTE: UTF-8 does not work!
$text= preg_replace('/&#(\d+);/me',"chr(\\1)",$text); #decimal notation
$text= preg_replace('/&#x([a-f0-9]+);/mei',"chr(0x\\1)",$text); #hex notation
return $text;
}
echo decode_entities("For tiden er neste president i det afrikanske landet Burkina Faso 11 år
");
echo html_entity_decode("For tiden er neste president i det afrikanske landet Burkina Faso 11 år
",'UTF-8');
我正在使用上述函数从字符串中解码 HTML 实体,但在解码特殊字符时显示不正确,例如 �。
Demo
【问题讨论】: