我在我的网站上有一个允许使用HTML的输入表单,我正在尝试添加关于使用HTML标签的说明。我想让这文本

<strong>Look just like this line - so then know how to type it</strong>

但目前为止我只知道

看起来就像这一行,这样你就知道怎么打了

我如何显示标签,让人们知道该输入什么?


当前回答

你可以使用htmlentities当回显到浏览器,这将显示标签,而不是让html解释它。

请看这里http://uk3.php.net/manual/en/function.htmlentities.php

例子:

 echo htmlentities("<strong>Look just like this line - so then know how to type it</strong>"); 

输出:

<strong>Look just like this line - so then know how to type it</strong>

其他回答

你只需要编码<>s:

&lt;strong&gt;Look just like this line - so then know how to type it&lt;/strong&gt;

将<替换为&lt;>和&gt;

你应该使用htmlspecialchars。它替换字符如下:

&(&)变成& (双引号)变成"当没有设置ENT_NOQUOTES时。 '(单引号)变成&#039;仅当设置了ENT_QUOTES时。 <(小于)变成&lt; >(大于)变成&gt;

在PHP中使用htmlspecialchars()函数来转义<和>。

htmlspecialchars('<strong>something</strong>')

要在浏览器中显示HTML标记,可以用< xmp>和< / xmp>标记包围输出