我的网站上有一个允许HTML的输入表单,我正在尝试添加有关HTML标记使用的说明.我想要的文字
<strong>Look just like this line - so then know how to type it</strong>
Run Code Online (Sandbox Code Playgroud)
但到目前为止,我得到的是:
看起来就像这一行 - 所以然后知道如何键入它
如何显示标签以便人们知道要键入什么?
Dar*_*arm 269
更换<
由<
并且>
通过>
acm*_*cme 228
在PHP中使用函数htmlspecialchars()来转义<
和>
.
htmlspecialchars('<strong>something</strong>')
Run Code Online (Sandbox Code Playgroud)
Jar*_*rod 49
正如许多其他人所说的那样,htmlentities()
会做到这一点......但它看起来很糟糕.
用<pre>
标签包裹它,你会保留你的缩进.
echo '<pre>';
echo htmlspecialchars($YOUR_HTML);
echo '</pre>';
Run Code Online (Sandbox Code Playgroud)
Lui*_*mim 36
你应该用htmlspecialchars
.它替换如下字符:
&
"
在未设置ENT_NOQUOTES时变为.'
仅在设置了ENT_QUOTES 时才会出现.<
>
Nik*_* K. 13
你可以使用htmlspecialchars()
<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // <a href='test'>Test</a>
?>
Run Code Online (Sandbox Code Playgroud)
您只需要编码<>
s:
<strong>Look just like this line - so then know how to type it</strong>
Run Code Online (Sandbox Code Playgroud)