tags:

views:

70

answers:

4

I am trying to output a text value from a php array. The value is

<Carlos>

However when echo'd to the page nothing shows because the browser has transformed it to

<Carlos></Carlos>

How do I stop it from transforming it into tags?

+10  A: 

Escape it, for example using htmlentities(). You'd end up with:

&lt;Carlos&gt;
Max Shawabkeh
thank you very much
Alex Crooks
(`htmlspecialchars` is normally to be preferred. `htmlentities` will usually-needlessly encode all non-ASCII characters, and if you don't tell it your encoding it will mess them up badly. `htmlspecialchars` only entity-references the few characters that really need it.)
bobince
+1  A: 

Do you mean you want to print

&lt;Carlos&gt;

? Apply htmlentities on the string to echo.

KennyTM
+1  A: 

if all you've written on the page is <Carlos> HTML won't automatically parse it to <Carlos></Carlos>. I reckon its the view source of your browser.

try

&lt;Carlos&gt;

Glycerine