How to addslashes to the alt text. The problem is an unwanted single quote.
text is -> alt='Photo od additional paintings from Isaac Sutton's collection after unpacking'
should be -> alt='Photo od additional paintings from Isaac Sutton\'s collection after unpacking'
<img width='318' height='238' alt='Photo od additional paintings from Isaac Sutton's collection after unpacking' src='[!--$wcmUrl('resource','groups/public/documents/image/kppcont_083705.jpg')--]' title='Additional paintings from Isaac Sutton's collection after unpacking' />
Use double quotes around the alt tag instead of the single quotes.
<img alt="Photo od additional paintings from Isaac Sutton's collection after unpacking" ... />
"How to addslashes?"
By using addslashes()
!
$txt = "Photo od additional paintings from Isaac Sutton's collection after unpacking";
$txt = addslashes($txt);
Having said that, even with a slash this won't work in your alt
and title
attributes since \
isn't an HTML escape character.
You either need to use double quotes in your <img>
tag attributes, or using htmlentities()
like this:
$txt = htmlentities($txt, ENT_QUOTES);
You will have to escape the value before using it in a HTML attribute. A backslash before the single quote will not work. In HTML/XML single quotes are escaped as an entity.
If you use DOM to create the HTML, it will take care of the escaping. If you create the HTML as text, htmlspecialchars() can do the job.
$text = "Additional paintings from Isaac Sutton's collection after unpacking";
var_dump(htmlspecialchars($text, ENT_QUOTES | ENT_HTML401));
Output:
string(72) "Additional paintings from Isaac Sutton's collection after unpacking"
<?php
$alt=htmlentities("Photo od additional paintings from Isaac Sutton's collection after unpacking");
?>
<img src="aamra24_ahmed_shafi1.jpg" width="473" height="347" alt="<?=$alt?>" />
<img width='318' height='238' alt='<?=$alt?>' src='[!--$wcmUrl('resource','groups/public/documents/image/kppcont_083705.jpg')--]' title='<?=$alt?>' />