我需要在屏幕上打印HTML标签作为文本(而不是代码).
我需要读者逐字阅读标签.
这样做的最佳做法是什么?
print htmlspecialchars('<meta name="copyright" content="© Winston Smith, 1984">');
Run Code Online (Sandbox Code Playgroud)
要么
print htmlentities('<meta name="copyright" content="© Winston Smith, 1984">');
Run Code Online (Sandbox Code Playgroud)
或者以上都不是.
*编辑I*
我已经通过htmlentities()看到了字符"©"的问题.这只能证实我的怀疑 - 哪一个可以安全地用于所有情况 - 还有另一种方法将html标签打印成文本吗?
Nie*_*sol 10
基本上你真正需要将HTML作为文本可读的是:
$out = strtr($input,Array("<"=>"<","&"=>"&"));
Run Code Online (Sandbox Code Playgroud)
htmlspecialchars基本上是一个子集htmlentities.htmlentities编码具有实体替代的一切,即所有命名实体和少数代码.
| 归档时间: |
|
| 查看次数: |
12062 次 |
| 最近记录: |