我正在使用Instagram的api将一些照片反馈到我的数据库中,然后使用javascript地图插件(ammap)显示它们。问题是,人们在他们的照片中发布了各种奇怪的角色和时髦的东西。描述。
在以下描述中,我得到了一个未捕获的SyntaxError:Unexpected token ILLEGAL
Walking to the Devils Punchbowl Falls in the rain would have been fun if it hadn't been for all the steps. Hardest kilometre I have ever have to trudge! In the end this 130m falls was worth all the effort.
Have a great day.
#all_my_own #au_nz_hotshotz #capturenz #exploring_the_world_21 #hot_shotz #ig_newzealand #inzed #kiwi #nzmustdo #nature_isa #newzealand #nzroadtrip #natureaddict #ourlonelyplanet #roadtrip #travel #thetravelbible #worldbestgram #fpog #arthurspass #purenewzealand
我如何使用数据
然后我在脚本中使用它如下
描述:"'边界=' 0'风格='填充:15像素;' />
"
现在我注意到即使在stackoverflow中代码也没有呈现。
这是一个小提琴http://jsfiddle.net/BrRe9/
这是我在php中做的事情
while ($row = mysql_fetch_assoc($getData)){
$retdata[] = array(
'desc' => $row['desc'],
....
然后这是我在javascript中做的事情
var dataProvider = {
map: "worldLow",
images:[
<?foreach($retdata as $rr):?>
{
description:"<div style='width:100%;margin:0 auto;text-align:center;'><p><?php echo addslashes($rr['desc']);?></p><div>"
},
<? endforeach;?>
]
};
答案 0 :(得分:0)
你需要告诉PHP“转义”描述,因为它可能包含会导致无效Javascript的字符。
在插入说明的地方尝试:
<?php echo json_encode(addslashes($rr['desc'])); ?>
答案 1 :(得分:0)
“如果您可以将PHP返回的描述转换为变量('desc'),请在javascript中对它执行任何操作之前尝试:
var newDesc = desc.replace(/[|&;$%@"<>()+,:]/g, "").replace(/'/g, "\'");
这应该删除大多数通常的时髦嫌疑人并逃脱单引号。