PHP converts this string to an array. at the end of this post, tangl198710 and 2011-08-1211:55 edit the string as follows: {aid: 21, ctl_a_cpu: df, ctl_a_ram: df, ctl_a_disk: df, ctl_a_fip: df, ctl_a_ OS: c_1_2 PHP how to convert such a string into an array
This post was last edited by tangl198710 at 12:11:55
The string is as follows:
{'Aid ': '21', 'ctl _ a_cpu': 'df ', 'ctl _ a_ram': 'df ', 'ctl _ a_disk': 'df ', 'ctl _ a_fip': 'df ', 'ctl _ a_ OS': 'c _ 1_2 ', 'ctl _ a_ OS _lang': 'c _ 4_1, c_4_3 ', 'Comment ': 'other requirements \ ', \ 'Haha \', \ '', 'total': '000000', 'typeid': '6 '}
How can I convert such a string into an array?
Convert the above string to an array: What is the value after the subscript before the number?
Share:
------ Solution --------------------
Well .. As a result, json_decode () cannot be directly used for processing. the manual conversion method is changed:
$ Str = <
{'Aid ': '21', 'ctl _ a_cpu': 'df ', 'ctl _ a_ram': 'df ', 'ctl _ a_disk': 'df ', 'ctl _ a_fip': 'df ', 'ctl _ a_ OS': 'c _ 1_2 ', 'ctl _ a_ OS _lang': 'c _ 4_1, c_4_3 ', 'Comment ': 'other requirements \ ', \ 'Haha \', \ '', 'total': '000000', 'typeid': '6 '}
EOF;
$ Ar = explode ("','", substr ($ str, 2,-2 ));
$ Result = '';
Foreach ($ ar as $ v ){
$ Ar_tmp = explode ("':'", $ v );
$ Result [$ ar_tmp [0] = $ ar_tmp [1];
}
Echo'';
print_r($result);