问题
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 "<label> AAAA"
http://www.w3schools.com/tags/ref_entities.asp
回答7:
echo "<label> AAAAA";
回答8:
Use HTML entities: <
for <
and >
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