php 处理 json数据中含有双引号 或其他非法字符的解决办法

2017-01-24  本文已影响0人  1663ea0b3a5d
function jsonString($s) {  
        $temp = preg_split('/(?<!^)(?!$)/u', $s );
        $n = count($temp); 
        for ($i = 0; $i < $n; $i++) {  
            if ($temp[$i] == ':' && $temp[$i + 1] == '"') {  
                for ($j = $i + 2; $j < $n; $j++) {  
                    if ($temp[$j] == '"') {  
                        if ($temp[$j + 1] != ',' && $temp[$j + 1] != '}') {  
                            $temp[$j] = '”';  
                        } else if ($temp[$j + 1] == ',' || $temp[$j + 1] == '}') {  
                            break;  
                        } else if($temp[$j] == '-'){  
                            $temp[$j] = ' ';  
                        }
                    }  
                }  
            }  
        }  
        return implode('',$temp);  
    }

辅导费

上一篇 下一篇

猜你喜欢

热点阅读