Re: HTML Escaping

From: Date: Fri, 23 Jul 2004 18:43:29 +0000
Subject: Re: HTML Escaping
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-191675@lists.php.net to get a copy of this message
Robb Kerr wrote:
I've got a conditional button that needs to appear/hide on my page depending upon the contents of a field in my database. The button is an image and has a long URL and JavaScript for image rotation attached to it. Needless to say, the href is quite long and includes several "'" characters. My conditional works great but I want to know if there is an easy way to escape the whole href so that the "'" characters will not be seen as PHP quote marks. See below... <?php if ($recordset['field'] != "1") { echo '<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('PreviousPage','','/URL/ButtonName.gif',1)"><img src="/URL/ButtonName.gif" alt="Previous Page" name="Previous Page" width="150" height="20" border="0"></a>; ?>
It looks like you're trying to echo a string that's delimited by single quote marks, but I don't see a single quote at the end of the string. Assuming this is what you want, though, to escape single quotes within the string you're trying to echo, put a backslash \ character before them. <?php if ($recordset['field'] != "1") { echo '<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'PreviousPage\',\'\',\'/URL/ButtonName.gif\',1)"><img src="/URL/ButtonName.gif" alt="Previous Page" name="Previous Page" width="150" height="20" border="0"></a>'; ?> Alternatively, you can just use double quotes in your JavaScript MM_swapImage() function... -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#191675) next »