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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:26:37  来源:igfitidea点击:

HTML,PHP - Escape '<' and '>' symbols while echoing

phphtmlescaping

提问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

Use htmlspecialchars.

使用htmlspecialchars

<?php
    echo htmlspecialchars("abc & < >");
?>

回答by Hadi Mostafapour

echo htmlentities("<label> AAAAA");

回答by itachi

<?php
    $string = "<label> AAAAA"; //whatever you want
    echo htmlspecialchars($string);
?>

refrencehtmlspecialchars

参考htmlspecialchars

回答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 "&lt;label&gt; AAAA"

echo "&lt;label&gt; AAAA"

http://www.w3schools.com/tags/ref_entities.asp

http://www.w3schools.com/tags/ref_entities.asp

回答by Rawkode

echo "&lt;label&gt; AAAAA";

回答by shadyyx

Use HTML entities: &lt;for <and &gt;for >. Could be achieved using htmlspecialcharsfunction: http://php.net/htmlspecialchars.

使用 HTML 实体:&lt;for<&gt;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