Re: Encoding for W3C Validation
| From: | Sebastian Ewert | Date: | Tue, 03 Aug 2010 19:15:06 +0000 |
| Subject: | Re: Encoding for W3C Validation | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-307304@lists.php.net to get a copy of this message | ||
Ashley Sheridan wrote:
> On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:
>
>> On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
>>
>>> Rick Dwyer wrote:
>>>> Hello List.
>>>>
>>>> In the Alt section of the IMG tag below, the variable $myitem has a value of
>>>> "Who's There".
>>>>
>>>> echo "<div class='myclass'><a href='#'
>>>> class='color_thumb'> <img src='/itemimages/$mypic' alt='$myitem'
>>>> width='60' ....
>>>>
>>>> When running through W3C validator, the line errors out because of the "
>>>> ' " in "Who's".
>>>> I tried:
>>>> $myitem=(htmlentities($myitem));
>>>>
>>>> But this has no affect on "Who's".
>>>>
>>>> What's the best way to code this portion so the apostrophe is handled
>>>> correctly?
>>>>
>>>>
>>>> TIA,
>>>>
>>>> --Rick
>>>>
>>>>
>>>>
>>>>
>>> Use it
>>>
>>>
>>> echo '<div class="myclass"><a href="#"
>>> class="color_thumb"> <img
>>> src="/itemimages/'.$mypic.'" alt="'.$myitem.'"
>>> width="60" ...'
>>
>> Thanks Sebastian.
>>
>> In the above, what is the function of the period in front of $myitem?
>>
>> --Rick
>>
>>
>
>
> It is a string concatenation in PHP. But, as my last email on this
> thread shows, you only need to add ENT_QUOTES to your htmlentities()
> call and everything will work.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
If you use single quotes you can't use variables inside the string. You
have to combine strings and variables or two strings with a dot.
echo 'foo'.$bar;
http://www.php.net/manual/de/language.types.string.php
I'm not shure but I think to validate xhtml you need the double quotes.