开发者

double qoutes in variables causing javascript error

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]')" >'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜