[PHP] HTML Escaping
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; ? Thanx in advance, Robb -- Robb Kerr Digital IGUANA Helping Digital Artists Achieve their Dreams http://www.digitaliguana.com http://www.cancerreallysucks.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML Escaping
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... urlencode will escape the quotes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML Escaping
Took me a little while to figure out what you were asking. You can do something like this for easy readability. ?php if ($recordset['field'] != 1) { ? 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 ?php } other php code ? You can close out your php declaration at any time and just put in regular text. It's a lot easier doing it this way than echo'ing many lines and you don't have to worry about escaping quotes. On Jul 23, 2004, at 2:07 PM, 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; ? Thanx in advance, Robb -- Robb Kerr Digital IGUANA Helping Digital Artists Achieve their Dreams http://www.digitaliguana.com http://www.cancerreallysucks.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Brent Baisley Systems Architect Landover Associates, Inc. Search Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML Escaping
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML Escaping
On Fri, 23 Jul 2004 14:43:29 -0400, John W. Holmes wrote: 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... Thanx. That's the escape character I needed. But, I've choosen to use the style Brent suggested above. It'll be easier than remembering to escape every single quote character. -- Robb Kerr Digital IGUANA Helping Digital Artists Achieve their Dreams http://www.digitaliguana.com http://www.cancerreallysucks.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML Escaping
On Fri, 23 Jul 2004 14:23:27 -0400, Brent Baisley wrote: Took me a little while to figure out what you were asking. You can do something like this for easy readability. ?php if ($recordset['field'] != 1) { ? 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 ?php } other php code ? You can close out your php declaration at any time and just put in regular text. It's a lot easier doing it this way than echo'ing many lines and you don't have to worry about escaping quotes. On Jul 23, 2004, at 2:07 PM, 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; ? Thanx in advance, Robb -- Robb Kerr Digital IGUANA Helping Digital Artists Achieve their Dreams http://www.digitaliguana.com http://www.cancerreallysucks.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Thanx. That works great. And, it's easy to read and update without having to remember to escape everything. -- Robb Kerr Digital IGUANA Helping Digital Artists Achieve their Dreams http://www.digitaliguana.com http://www.cancerreallysucks.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php