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

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.



Solution 1:[1]

echo htmlentities("<label> AAAAA");

Solution 2:[2]

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

refrence htmlspecialchars

Solution 3:[3]

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

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

Solution 4:[4]

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

echo htmlentities ("<label> AAAAA");

Solution 5:[5]

You should escape your especial characters for HTML.

echo "&lt;label&gt; AAAA"

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

Solution 6:[6]

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

Solution 7:[7]

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

Solution 8:[8]

Comment by ADyson worked:

while($rile = -> if($rile =... then it will just fetch the first item returned by the query, if any, and won't loop through all of them.

I replaced while with if.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hadi Mostafapour
Solution 2 itachi
Solution 3 0b10011
Solution 4 Tom
Solution 5 Enrique Paredes
Solution 6 Rawkode
Solution 7 shadyyx
Solution 8 Elikill58