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

家住魔仙堡 提交于 2019-12-17 09:57:10

问题


I want to print following text as it is:

echo "<label> AAAAA";

But it is just showing 'AAAAA' as output.

How can I escape '<' and '>' symbol.


回答1:


Use htmlspecialchars.

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



回答2:


echo htmlentities("<label> AAAAA");



回答3:


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

refrence htmlspecialchars




回答4:


Use the htmlentities() function to convert into a plain text string.

<?php
echo htmlentities("<label> AAAAA");
?>



回答5:


check this http://php.net/manual/en/function.htmlentities.php, and this is code -

echo htmlentities ("<label> AAAAA");



回答6:


You should escape your especial characters for HTML.

echo "&lt;label&gt; AAAA"

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




回答7:


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



回答8:


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

Read more about HTML entities here: http://www.santagata.us/characters/CharacterEntities.html



来源:https://stackoverflow.com/questions/10551116/html-php-escape-and-symbols-while-echoing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!