PHP html_entity_decode 没有按预期解码实体?

PHP html_entity_decode Doesn't Decode Entity as Expected?

在下面的代码中:

$string1 = "function doesn't work as expected";
$string2 = html_entity_decode($string1);

$string2 仍然包含:

 '

...在调用 html_entity_decode() 之后。

我已经检查了有关此主题的其他 SO 线程,但尚未找到答案。我错过了什么?

html_entity_decodedefault flags 不包含单引号。尝试更新您的标志参数以包括 ENT_QUOTESENT_HTML5:

$string1 = "function doesn't work as expected";
echo $string2 = html_entity_decode($string1, ENT_QUOTES|ENT_HTML5);
// function doesn't work as expected