HTML,PHP - 回显时转义“<”和“>”符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10551116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML,PHP - Escape '<' and '>' symbols while echoing
提问by AnonGeek
I want to print following text as it is:
我想按原样打印以下文本:
echo "<label> AAAAA";
But it is just showing 'AAAAA' as output.
但它只是显示“AAAAA”作为输出。
How can I escape '<' and '>' symbol.
如何转义 '<' 和 '>' 符号。
回答by Oscar Broman
回答by Hadi Mostafapour
echo htmlentities("<label> AAAAA");
回答by itachi
<?php
$string = "<label> AAAAA"; //whatever you want
echo htmlspecialchars($string);
?>
refrencehtmlspecialchars
回答by Userbn
Use the htmlentities()function to convert into a plain text string.
使用该htmlentities()函数转换为纯文本字符串。
<?php
echo htmlentities("<label> AAAAA");
?>
回答by Tom
check this http://php.net/manual/en/function.htmlentities.php, and this is code -
检查这个http://php.net/manual/en/function.htmlentities.php,这是代码 -
echo htmlentities ("<label> AAAAA");
回答by Enrique Paredes
You should escape your especial characters for HTML.
您应该为 HTML 转义您的特殊字符。
echo "<label> AAAA"
echo "<label> AAAA"
回答by Rawkode
echo "<label> AAAAA";
回答by shadyyx
Use HTML entities: <for <and >for >. Could be achieved using htmlspecialcharsfunction: http://php.net/htmlspecialchars.
使用 HTML 实体:<for<和>for >。可以使用htmlspecialchars函数实现:http: //php.net/htmlspecialchars。
Read more about HTML entities here: http://www.santagata.us/characters/CharacterEntities.html
在此处阅读有关 HTML 实体的更多信息:http: //www.santagata.us/characters/CharacterEntities.html

