您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP怎么将这样的字符串变成数组

2024/5/1 17:42:46发布31次查看
php如何将这样的字符串变成数组
本帖最后由 tangl198710 于 2011-08-12 12:11:55 编辑 字符串如下:
{'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':'其它要求\',\'呵呵\',\'','total':'1090','typeid':'6'}
这样的字符串怎么转换成数组使用了?
如上的字符串转换成数组  :号前的为下标 后面的是值   要怎么处理呢,望高手指点 分享到:
------解决方案--------------------
恩。。果然无法直接用json_decode()处理,改手工方式转换:
$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':'其它要求\',\'呵呵\',\'','total':'1090','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);
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product