Re: Escape characters in PHP ?

From: Date: Tue, 16 Nov 1999 12:37:48 +0000
Subject: Re: Escape characters in PHP ?
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-12600@lists.php.net to get a copy of this message
Thanks ! It works .. regds -mukul >Close, but no cigar. :) They're special characters in HTML. If you >run this script on the command line (requires CGI PHP to be built >first) or even just 'View source' in your browser, you'll probably >find that $var is printing fine. It's just that your browser sees '<', >and thinks a tag is starting. However, since browsers ignore tags they >don't understand, your browser effectively just tosses the 'MNRPQR' >and closing tag '>'; since it didn't understand the tag, it doesn't do >anything else about it (such as display it). > >To get around this, you'll want to use the htmlspecialchars() >function, which encodes these characters into HTML entities. This >allows them to just be shown without the browser trying to do anything >special with them. The documentation for the function is here: > > http://www.php.net/manual/function.htmlspecialchars.php3 > >The practical upshot of all this is: > ><?php >$var = 'ABCDEFGH:<MNRPQR>'; >echo htmlspecialchars( $var ); >?> > > >Torben -------------------------------------------------------------- Bharti Cellular Limited, New Delhi, India

« previous php.dev (#12600) next »