From: Rick Dwyer on
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



From: Sebastian Ewert on
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" ...'
From: Ashley Sheridan on
On Tue, 2010-08-03 at 14:41 -0400, 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
>
>
>
>


Well, because the way you're using htmlentities() there is ignoring
single quotes, i.e. not escaping them. Try myitem=htmlentities($myitem,
ENT_QUOTES); instead.

Also, as an aside, I think it's general acceptance to use double quotes
on HTML attributes rather than single. While that does make for
complications when the HTML is part of a double-quoted string in PHP, it
does avoid tricker problems surrounding Javascript event handlers on
code, which generally use single quotes when they are part of an HTML
attribute.

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: Shreyas Agasthya on
Rick,

Probably Sebastian's fix might work but *htmlspecialchars* can help you,
too.

Regards,
Shreyas

On Wed, Aug 4, 2010 at 12:17 AM, Sebastian Ewert <seb2015(a)yahoo.de> 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" ...'
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Regards,
Shreyas Agasthya
From: Rick Dwyer on

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