国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php接受表單提交的json字符串多了反斜杠,遇到一些處理字符串的問題,求解答
黃舟
黃舟 2017-04-10 15:16:53
0
3
390

["/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg","/Public/editor/php/../attached/image/20150115/20150115094110_19764.jpg"]
表單提交上面字符串,
php接收并輸出,結(jié)果是[\"/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg\",\"/Public/editor/php/../attached/image/20150115/20150115094110_19764.jpg\"]

百度了一下,使用stripslashes把反斜杠去掉后使用json_decode()轉(zhuǎn)化,結(jié)果為空。

$img=stripslashes($data['img']);
$img_list=json_decode($img);
$test='["/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg","/Public/editor/php/../attached/image/20150115/20150115094110_19764.jpg"]';
//$test內(nèi)容為輸入框里的字符串
if($test == $img) echo 1; //if語句不成立,沒有輸出1;

是什么情況啊。。。

黃舟
黃舟

人生最曼妙的風景,竟是內(nèi)心的淡定與從容!

reply all(3)
迷茫
<?php
function arrayEqual($array1,$array2){
    return !array_diff($array1,$array2) && !array_diff($array2,$array1);
}

樓主可以了解一下array_diff

Peter_Zhu

stripslashes后var_dump看下,是否是合法的json字串。 是不是有實體的雙引號 ?

黃舟

謝謝@star001007 提醒,其實那個引號不需要過濾,json字符串本來就是需要用""引起來的。提主直接json_decode就可以了

<?php 
$a = "[\"/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg\",\"/Public/editor/php/../attached/image/20150115/20150115094110_19764.jpg\"]";
$b = json_decode($a);
var_dump($b);

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template