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

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

但目前为止我只知道

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

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


当前回答

还有另一种方法……

header('Content-Type: text/plain; charset=utf-8');

这使得整个页面作为纯文本…更好的是htmlspecialchars…

希望这对你有所帮助……

其他回答

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

你可以使用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>

原生JavaScript方法-

('<strong>Look just ...</strong>').replace(/</g, '&lt;').replace(/>/g, '&gt;');

享受吧!

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

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

还有另一种方法……

header('Content-Type: text/plain; charset=utf-8');

这使得整个页面作为纯文本…更好的是htmlspecialchars…

希望这对你有所帮助……