编码等于符号到HTML等效的PHP

时间:2014-12-21 05:41:10

标签: php html encode

我尝试通过使用:

将'='符号编码为其html等效符号
htmlentities("This is my test and it = this");

结果是:

<p>This is my test and it = this</p>1

请注意等号不是如何编码的?我知道有一个HTML等价物。 我可以使用什么替代函数来编码这个字符串?

感谢。

2 个答案:

答案 0 :(得分:1)

无需对=进行编码;这是HTML安全的。但是,如果您真的想要:=

echo str_replace('=', '=', htmlentities("This is my test and it = this"));

Demo

答案 1 :(得分:1)

  

我知道有一个HTML等价物

等号不是为HTML编码的,没有理由这样做。

您可能会想到网址 - 编码,这将是%3d

urlencode("This is my test and it = this");
// => "This+is+my+test+and+it+%3D+this"