开发者

double qoutes in variables causing javascript error

开发者 https://www.devze.com 2022-12-09 14:32 出处:网络
In my below code when the $artist or $title variables contain \" it causes the JavaScript command to break.

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

精彩评论

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

关注公众号