private function replanStr($str)
{
$arr = [];
// 将“[”, “]” 和“"”替换成空白字符,“},”替换成“};”方便切割数组
$replaceStr = trim(str_replace(['[', ']'. '"', '},'], ['', '', '', '};'], $str);
// 切割“;”成数组
$explodeStr = explode(';', $replaceStr);
// 遍历[{},{}]索引数组
foreach ($explodeStr as $key => $val) {
// 置换空白字符
$replace = trim(str_replace(['{', '}'], ['', ''], $val));
// 切割成二级数组
$explode = explode(',', $replace);
foreach ($explode as $k => $v) {
if (is_null($v) || empty($val) || $val == '') {
continue;
}
$rep = str_replace('"', '', $val);
$expl = explode(':', $val); // key: val => [key,val]
// 组装新数组
$arr[$key][trim(0)] = trim($expl[1]);
}
}
return $arr;
}
|