In my below code when the $artist
or $title
variables contain " it causes the JavaScript command to break.
Is there another way I can encode these other than addslashes() to fix this?
$artist = addslashes($row['artist']);
$title = addslashes($row['title']);
echo '<div class="play" style="display: inline"><a href="javascript:playSong'."('$artist','$title开发者_高级运维','$row[file]','$row[id]')".'">
you can consider url encoding for variables, like
$artist = rawurlencode($row['artist']);
$title = rawurlencode($row['title']);
echo "..... playSong(unescape('$artist'), unescape('$title')... ";
or move decoding into playSong function.
// edit: this is how you get your quotes right
echo "<div class='play' style='display: inline'><a href=\"javascript:playSong(unescape('$artist'),unescape('$title'),'$row[file]','$row[id]')\">....";
You could try urlencode()
.
Try this
echo '<div class="play" style="display: inline">
<a href="javascript:playSong('$artist','$title','$row[file]','$row[id]')" >'
精彩评论