将数字实体转换为UTF-8

时间:2013-09-29 17:43:02

标签: php

如何用适当的UTF-8替换所有数字实体?

例如:在源代码中,字符串显示如下:

$string1 = "The Devil's in the Details";
$string2 = "Dónde estás, hermano?";

我需要用

替换它
echo string1; //OUTPUTS Should be: The Devil's in the details
echo string2; //OUTPUTS Should be: Dónde Estás, Hermano?

我试过html_entity_decode()但是没有用;任何想法?

1 个答案:

答案 0 :(得分:5)

如果html_entity_decode的问题是它没有解码',那是因为默认标志设置为解码所有单引号。不要试图问为什么会这样;它是PHP。

尝试ENT_QUOTES

html_entity_decode($str, ENT_QUOTES | ENT_HTML5); # HTML5 is good

That appears to work.