什么是htmlentities与字符串htmlentities完全一致?

时间:2012-06-07 20:44:11

标签: php

var_dump(htmlentities("<space>")); 

返回string(21) "<space>",

21 chars huh?

3 个答案:

答案 0 :(得分:2)

实际上它会返回其他内容:

<? var_dump(htmlentities("&lt;space&gt;")); ?>
string(21) "&amp;lt;space&amp;gt;"

您看到的是转义字符串的未转义版本:)。

答案 1 :(得分:1)

有空格或特殊格式。

"&amp;lt;space&amp;gt;" = 21个字符。

答案 2 :(得分:0)

因为它将&符号转换为HTML实体。

& => &amp;

所以,你真的最终得到了字符串:

&amp;lt;space&amp;gt;

这是21个字符。

您可以在浏览器中查看源代码,以查看上面的确切字符串。如果您不查看来源,则浏览器会将&amp;转换回&,这就是您只看到&lt;space&gt;的原因。