Prev: Re[2]: [PHP] Do you have some standard for defined the variablein program language?
Next: the state of the PHP community
From: Rick Dwyer on 29 Jul 2010 00:18 Hello List. I have variables displaying content from mysql fields. The contents contains & like "Dogs & Cats"... so naturally the W3C validator chokes on them. Is there a way to encode so they display properly on the page but the validator is OK with them? Is the answer as simple as: urlencode($myvar) Thanks, --Rick
From: Rick Dwyer on 29 Jul 2010 00:29 So htmlentities() will work for "Green, Red & Blue"? Will it work for "....htm?color=blue&number=2&letter=...."? --Rick On Jul 29, 2010, at 12:23 AM, Josh Kehn wrote: > Rick- > > Probably would use htmlentities() instead. You could also do str_replace("&", "&"); > > Regards, > > -Josh > > On Jul 29, 2010, at 12:18 AM, Rick Dwyer wrote: > >> Hello List. >> >> I have variables displaying content from mysql fields. The contents contains & like "Dogs & Cats"... so naturally the W3C validator chokes on them. >> >> Is there a way to encode so they display properly on the page but the validator is OK with them? >> >> >> Is the answer as simple as: >> >> urlencode($myvar) >> >> Thanks, >> --Rick >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >
From: Rick Dwyer on 29 Jul 2010 00:35 Exactly what I was looking for! Thanks Josh. --Rick On Jul 29, 2010, at 12:33 AM, Josh Kehn wrote: > Rick- > > Give it a try! > > <?php > $test_one = "Green, Red & Blue"; > $test_two = "htm?color=blue&number=2&letter=a"; > > echo htmlentities($test_one); // Green, Red & Blue > echo htmlentities($test_two); // htm?color=blue&number=2&letter=a > > ?> > > Regards, > > -Josh > > On Jul 29, 2010, at 12:29 AM, Rick Dwyer wrote: > >> So htmlentities() will work for "Green, Red & Blue"? >> >> Will it work for "....htm?color=blue&number=2&letter=...."? >> >> --Rick >> >> >> >> >> >> On Jul 29, 2010, at 12:23 AM, Josh Kehn wrote: >> >>> Rick- >>> >>> Probably would use htmlentities() instead. You could also do str_replace("&", "&"); >>> >>> Regards, >>> >>> -Josh >>> >>> On Jul 29, 2010, at 12:18 AM, Rick Dwyer wrote: >>> >>>> Hello List. >>>> >>>> I have variables displaying content from mysql fields. The contents contains & like "Dogs & Cats"... so naturally the W3C validator chokes on them. >>>> >>>> Is there a way to encode so they display properly on the page but the validator is OK with them? >>>> >>>> >>>> Is the answer as simple as: >>>> >>>> urlencode($myvar) >>>> >>>> Thanks, >>>> --Rick >>>> >>>> >>>> -- >>>> PHP General Mailing List (http://www.php.net/) >>>> To unsubscribe, visit: http://www.php.net/unsub.php >>>> >>> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >
From: Shawn McKenzie on 29 Jul 2010 17:01
On 07/28/2010 11:29 PM, Rick Dwyer wrote: > So htmlentities() will work for "Green, Red & Blue"? > > Will it work for "....htm?color=blue&number=2&letter=...."? > > --Rick For ampersands yes, for other things no. Use the correct tool for the job. To output HTML use htmlentities(). To pass in the URL use urlencode(). At some point you're going to have a value that contains a = or ? or something else that you need to pass in the URL. That's what urlencode() is for. > > > On Jul 29, 2010, at 12:23 AM, Josh Kehn wrote: > >> Rick- >> >> Probably would use htmlentities() instead. You could also do str_replace("&", "&"); >> >> Regards, >> >> -Josh >> >> On Jul 29, 2010, at 12:18 AM, Rick Dwyer wrote: >> >>> Hello List. >>> >>> I have variables displaying content from mysql fields. The contents contains & like "Dogs & Cats"... so naturally the W3C validator chokes on them. >>> >>> Is there a way to encode so they display properly on the page but the validator is OK with them? >>> >>> >>> Is the answer as simple as: >>> >>> urlencode($myvar) >>> >>> Thanks, >>> --Rick >>> >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> > -- Thanks! -Shawn http://www.spidean.com |