【问题标题】:Encoding equals symbol to html equivalent php [closed]编码等于符号到html等效php [关闭]
【发布时间】:2014-12-21 05:41:10
【问题描述】:

我尝试通过使用以下方法将“=”符号编码为其 html 等效项:

htmlentities("This is my test and it = this");

结果是:

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

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

谢谢。

【问题讨论】:

  • 给出的示例不正确(传递的参数中没有 HTML 标记)。该问题声称有一个 HTML 等价物,但没有说明它是什么,也没有说明应该执行什么“编码”(或为什么)。

标签: php html encode


【解决方案1】:

我知道有一个 HTML 等价物

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

您可能正在考虑 URL-编码,即%3d:

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

【讨论】:

    【解决方案2】:

    = 无需编码;它是 HTML 安全的。不过,如果你真的想这样做:=

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

    Demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-17
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 2013-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多