6

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

$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: '
4

2 回答 2

18

就在这里: htmlspecialchars_decode($string, ENT_QUOTES);

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

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

编辑:我做了测试,它确实有效:)

于 2013-05-18T01:21:59.480 回答
6

您可以使用html_entity_decode()

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

看看它在行动:http ://sandbox.onlinephpfunctions.com/code/7f4649eb47a8e639c514787a100b63bbad4bc8c6

于 2013-05-18T01:22:27.867 回答