Re: [PHP] Encoding Ampersands

[email protected] (Rick Dwyer)
Newsgroups php.general
Message-ID <[email protected]>
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 &amp; Blue
> echo htmlentities($test_two); // htm?color=blue&amp;number=2&amp;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("&", "&amp;");
>>> 
>>> 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
>> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.