$str = 'array("1"=>"给对方","2"=>"发鬼地方","5"=>"","6"=>"发鬼地方","7"=>"发光飞碟");';
参考@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] => 发光飞碟 )
思路:
去掉开头的array(和最后的);,变成:
array(
);
'"1"=>"给对方","2"=>"发鬼地方","5"=>"","6"=>"发鬼地方","7"=>"发光飞碟"'
把=>替换成:,变成:
=>
:
'"1":"给对方","2":"发鬼地方","5":"","6":"发鬼地方","7":"发光飞碟"'
前后加{},变成:
{}
'{"1":"给对方","2":"发鬼地方","5":"","6":"发鬼地方","7":"发光飞碟"}'
上json_decode
json_decode
用正则处理,前提是你的value里面不会有 => 这样的文字
参考@oraoto
思路:
去掉开头的
array(
和最后的);
,变成:把
=>
替换成:
,变成:前后加
{}
,变成:上
json_decode
用正则处理,前提是你的value里面不会有 => 这样的文字