11 个答案:
答案 0 :(得分:248)
将替换为>
答案 1 :(得分:221)
在PHP中使用函数htmlspecialchars()来转义。
htmlspecialchars('something')
答案 2 :(得分:48)
正如其他许多人所说,htmlentities()会做到这一点......但它看起来很糟糕。
使用
标记进行包装,您将保留缩进。
echo '
';
echo htmlspecialchars($YOUR_HTML);
echo '
';答案 3 :(得分:36)
'&安培;' (&符号)变为&
'“'(双引号)在未设置ENT_NOQUOTES时变为"。
“'”(单引号)仅在设置ENT_QUOTES时变为'。
'&LT;' (小于)变为<
'&GT;' (大于)变为>
答案 4 :(得分:13)
你可以使用htmlspecialchars()
$new = htmlspecialchars("Test", ENT_QUOTES);
echo $new; // <a href='test'>Test</a>
?>
答案 5 :(得分:6)
要在浏览器中显示HTML标记,请使用&lt; XMP&GT;和&lt; / xmp&gt;标签
答案 6 :(得分:5)
您只需要编码<> s:
<strong>Look just like this line - so then know how to type it</strong>
答案 7 :(得分:3)
您可以在回显浏览器时使用htmlentities,这将显示标记,而不是让html解释它。
示例:
echo htmlentities("Look just like this line - so then know how to type it");
输出:
Look just like this line - so then know how to type it
答案 8 :(得分:1)
使用htmlentities()转换否则将显示为HTML的字符。
答案 9 :(得分:0)
原生JavaScript方法-
('Look just like ...').replace(//g, '>');
享受!
答案 10 :(得分:0)
还有另一种方法...
header('Content-Type: text/plain; charset=utf-8');
这使得整个页面都可以用作纯文本...更好的是htmlspecialchars ...
希望这对您有帮助...