Page 1 of 1

How to literally echo the greater than and less than signs?

Posted: Mon Nov 09, 2009 2:54 pm
by daneditty
echo "<noreply@mysite.com>";

The result is blank when you view this with a browser. PHP reads < > as html tags. How can I literally echo <>, so they show up in my browser just like <> or so I can set <noreply@mysite.com> to a variable and echo the variable?

Re: How to literally echo the greater than and less than signs?

Posted: Mon Nov 09, 2009 3:22 pm
by Apollo
daneditty wrote:PHP reads < > as html tags.
No, PHP doesn't, but your browser does (because it expects html, not plain text).

Try the htmlspecialchars function:

Code: Select all

$myAddress = "<noreply@yoursite.com>";
echo htmlspecialchars($myAddress);
This will replace the < and > characters with < and > which is correctly displayed by browsers.

Re: How to literally echo the greater than and less than signs?

Posted: Mon Nov 09, 2009 3:31 pm
by daneditty
Muchas gracias!

You rock!