How does PHP convert such a string into an array?

Source: Internet
Author: User
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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.