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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daneditty
Forum Newbie
Posts: 6
Joined: Fri Nov 06, 2009 10:27 am

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

Post 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?
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

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

Post 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.
daneditty
Forum Newbie
Posts: 6
Joined: Fri Nov 06, 2009 10:27 am

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

Post by daneditty »

Muchas gracias!

You rock!
Post Reply