取代,# 39;以及具有相应字符的类似HTML代码


Replace ' and similar html codes with their correspondent character?

所以我有一个像这样的字符串:

$string = "This is a test string. It has characters like these: '";

是否有一个php函数将这些字符转换为相应的字符,在我的例子中,期望的输出将是:

print $string
// OUTPUT: This is a test string. It has characters like these: '

有:htmlspecialchars_decode($string, ENT_QUOTES);

不确定具体的'字符,据我所知htmlspecialchars(带有ENT_QUOTES标志)将撇号(')转换为'(带有前导零)

所以'上的确切行为值得检查

编辑:我做了测试,它确实工作:)

可以使用html_entity_decode()

就像反向的htmlentities。如果在输入字符串中使用引号,则必须将html_entity_decode()的第二个参数设置为ENT_QUOTES

实际操作:http://sandbox.onlinephpfunctions.com/code/7f4649eb47a8e639c514787a100b63bbad4bc8c6