用于将html实体转换回html特殊字符的PHP函数


PHP function for converts html entities back to html special characters

我有这个函数可以将html实体转换回html特殊字符:

function html_entity_decode_utf8($value, $double_encode = TRUE) 
{
    return htmlspecialchars( (string) $value, ENT_QUOTES, "UTF-8", $double_encode);

}

现在,我需要打印这个:

echo html_entity_decode_utf8('&zwnj');

输出为:

&zwnj

为什么htmlspecialchars不工作?!我该怎么解决这个问题?

htmlspecialchars&转换为&。要转换回,您需要htmlspecialchars_decode:

function html_entity_decode_utf8($value) 
{
    return htmlspecialchars_decode( (string) $value, ENT_QUOTES);
}

要查看使用此功能的更多选项,请查看文档。