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

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

作者: 1663ea0b3a5d | 来源:发表于2017-01-24 18:16 被阅读0次
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);  
    }

辅导费

相关文章

网友评论

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

      本文链接:https://www.haomeiwen.com/subject/jvozbttx.html