I have code loading in the titles of some films into the title attribute of their respective thumbnails, this format is thus:
Artist Name – ‘Song Title’
I had this code initially:
$return .= "' title='";
$return .=$video['title'];
$return .= "'>";
Obviously the first single quote was causing the title attribute to end prematurley, so I changed it to:
$return .= "' title='";
$return .= htmlspecialchars($video['title']);
$return .= "'>";
Which has had not effect at all, all the titles are still ending prematurely.
Am I misunderstanding the htmlspecialchars method?
http://php.net/manual/en/function.htmlspecialchars.php
By default,
htmlspecialchars()does not escape single quotes (some ancient compatibility behavior). Usehtmlspecialchars($video['title'], ENT_QUOTES).You also probably should pass ‘utf-8’ as the third argument. I wrapped this deprecated behavior like this: