$str = 'array("1"=>"给对方","2"=>"发鬼地方","5"=>"","6"=>"发鬼地方","7"=>"发光飞碟");';
迷茫2017-04-11 10:05:24
参考@oraoto
$str = 'array("1"=>"给对方","2"=>"发鬼地方","5"=>"","6"=>"发鬼地方","7"=>"发光飞碟");';
$s= str_replace(['array(','=>',');'],['{',':','}'],$str);
print_r(json_decode($s,1));
Array
(
[1] => 给对方
[2] => 发鬼地方
[5] =>
[6] => 发鬼地方
[7] => 发光飞碟
)
伊谢尔伦2017-04-11 10:05:24
思路:
去掉开头的array(
和最后的);
,变成:
'"1"=>"给对方","2"=>"发鬼地方","5"=>"","6"=>"发鬼地方","7"=>"发光飞碟"'
把=>
替换成:
,变成:
'"1":"给对方","2":"发鬼地方","5":"","6":"发鬼地方","7":"发光飞碟"'
前后加{}
,变成:
'{"1":"给对方","2":"发鬼地方","5":"","6":"发鬼地方","7":"发光飞碟"}'
上json_decode