PHP accepts the json string submitted by the form with more backslashes, and encounters some problems in processing strings, please answer
[“/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg”,”/Public/editor/php/../attached/image/20150115/20150115094110_19764.jpg”] Submit the above string in the form, php receives and outputs, the result is [\”/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg\”,\”/Public/editor/php/../attached/image/20150115/ 20150115094110_19764.jpg\”] Baidu, use stripslashes to remove the backslashes and use json_decode() to convert, the result is empty. $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”]’ ; //The content of $test is the string in the input box if($test == $img) echo 1; //if statement is not established, no output 1; What’s the situation. . . Response content: [“/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg”,”/Public/editor/php/../attached/image/20150115/20150115094110_19764.jpg”] Submit the above string in the form, php receives and outputs, the result is [\”/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg\”,\”/Public/editor/php/../attached/image/20150115/ 20150115094110_19764.jpg\”] Baidu, use stripslashes to remove the backslashes and use json_decode() to convert, the result is empty. $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”]’ ; //The content of $test is the string in the input box if($test == $img) echo 1; //if statement is not established, no output 1; What’s the situation. . . <?php function arrayEqual($array1, $array2){ return !array_diff($array1,$array2) && !array_diff($array2,$array1); } You can learn more about array_diff After stripslashes, check var_dump to see if it is a legal json string. Are there physical double quotes? Thank you @star001007 for reminding, in fact, the quotation mark does not need to be filtered, the json string needs to be enclosed by “”. You can just json_decode directly <?php $a =…
PHP accepts the json string submitted by the form with more backslashes, and encounters some problems in processing strings, please answer
[“/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg”,”/Public/editor/php/../attached/image/20150115/20150115094110_19764.jpg”] Submit the above string in the form, php receives and outputs, the result is [\”/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg\”,\”/Public/editor/php/../attached/image/20150115/ 20150115094110_19764.jpg\”] Baidu, use stripslashes to remove the backslashes and use json_decode() to convert, the result is empty. $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”]’ ; //The content of $test is the string in the input box if($test == $img) echo 1; //if statement is not established, no output 1; What’s the situation. . . Response content: [“/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg”,”/Public/editor/php/../attached/image/20150115/20150115094110_19764.jpg”] Submit the above string in the form, php receives and outputs, the result is [\”/Public/editor/php/../attached/image/20150115/20150115094109_33178.jpg\”,\”/Public/editor/php/../attached/image/20150115/ 20150115094110_19764.jpg\”] Baidu, use stripslashes to remove the backslashes and use json_decode() to convert, the result is empty. $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”]’ ; //The content of $test is the string in the input box if($test == $img) echo 1; //if statement is not established, no output 1; What’s the situation. . . <?php function arrayEqual($array1, $array2){ return !array_diff($array1,$array2) && !array_diff($array2,$array1); } You can learn more about array_diff After stripslashes, check var_dump to see if it is a legal json string. Are there physical double quotes? Thank you @star001007 for reminding, in fact, the quotation mark does not need to be filtered, the json string needs to be enclosed by “”. You can just json_decode directly <?php $a =…