文字列を配列に加工する
次のように、文字列 "{SUCESS=[ttt,111],ERROR=[rrr,ggg,vd]}" を配列
に加工する方法を教えてください。
array (
'SUCESS' => array(
[0] => 'ttt',
[1] => '111'
),
'ERROR'=> ; (
[0] => 'rrr',
[1] => 'ggg',
[2] => 'vd'
)
)
------解決策------------------
$s="{SUCESS=[ttt,111],ERROR=[rrr,ggg,vd]}"; preg_replace('/(w+)=[(.*?)]/e','$ar[$1]=explode(",","$2")',$s); print_r($ar); /* 配列 ( [成功] => ( [0] => [1] => 111 ) [エラー] => ( [0] => [1] => [2] => ) ) */ <div class="clear"></div>