joh*_*ohn 7 html php escaping echo
在PHP(Wordpress主题函数,尝试将存储在主题选项中的html添加到博客标题)中,我试图获得以下行:
$x="<p>html</p>"; echo $x;
Run Code Online (Sandbox Code Playgroud)
要呈现html,就像:
echo "<p>html</p>";
Run Code Online (Sandbox Code Playgroud)
结果不同,第一个将显示html标签,而第二个将处理html.有人可以请帮助.谢谢
Bab*_*aba 23
答:如果您想显示HTML标签,您可以使用 htmlentities
例
$x = "<p>html</p>";
echo htmlentities($x);
Run Code Online (Sandbox Code Playgroud)
产量
<p>html</p>
Run Code Online (Sandbox Code Playgroud)
B.如果你想要反过来可能你的字符串存储,因为
<p>html</p>这就是你看到的原因,<p>html</p>你应该使用html_entity_decode
例
$x = "<p>html</p>";
echo html_entity_decode($x);
Run Code Online (Sandbox Code Playgroud)
产量
html
Run Code Online (Sandbox Code Playgroud)
C.可能是你没有使用网络浏览器而你想要html那么你应该使用strip_tags
例
$x = "<p>html</p>";
echo strip_tags($x);
Run Code Online (Sandbox Code Playgroud)
产量
html
Run Code Online (Sandbox Code Playgroud)