我怎么能回应'<a>&#39; without it making a link?</a>

时间:2013-04-11 19:21:42

标签: php html

我希望在没有执行html的情况下回复以下内容:

<?php echo 'Allowable tags: <a><b>'; ?>

我该怎么做?

5 个答案:

答案 0 :(得分:3)

使用character entities

echo 'Allowable tags: &lt;a&gt;&lt;b&gt;';

答案 1 :(得分:3)

使用htmlentities会起作用:

<?php echo 'Allowable tags: ' . htmlentities('<a><b>'); ?>

答案 2 :(得分:0)

使用PHP htmlentities()将特殊字符转换为html实体,如下所示:

<?php echo htmlentities('Allowable tags: <a><b>'); ?>

答案 3 :(得分:0)

您可以使用HTML转义字符...

http://www.w3schools.com/tags/ref_entities.asp

答案 4 :(得分:0)

htmlspecialchars - 将特殊字符转换为HTML实体。

<?php echo htmlspecialchars('Allowable tags: <a><b>'); ?>

输出HTML:

Allowable tags: &lt;a&gt;&lt;b&gt;

见:

  

允许的标签:&lt; a&gt;&lt; b&gt;