Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP preg_replace_callback()编译失败:丢失)_Php_Compiler Errors_Anonymous Function - Fatal编程技术网

PHP preg_replace_callback()编译失败:丢失)

PHP preg_replace_callback()编译失败:丢失),php,compiler-errors,anonymous-function,Php,Compiler Errors,Anonymous Function,好的,我有这个小助手函数 public static function toJSON($arr){ $json = json_encode($arr); return preg_replace_callback('/(?<=:)"function((?:(?!}").)*}"/', function($string){

好的,我有这个小助手函数

public static function toJSON($arr){
        $json = json_encode($arr);
        return preg_replace_callback('/(?<=:)"function((?:(?!}").)*}"/',
                                    function($string){
                                        return str_replace(array('\"','/','"','n','t'),array('"','/','"','',''),substr($string[0],1,-1));
                                     },$json);
    }
公共静态函数toJSON($arr){
$json=json_encode($arr);

return preg_replace_callback('/(?中有一个未闭合的括号

'/(?<=:)"function((?:(?!}").)*}"/'

”/(?我很确定原作者的意图是:

'/(?<=:)"function((?:(?!}").)*})"/'
                               ^

这也会起作用(占用的内存也会少一点)。

不要让事情变得复杂。一步一步地做。嗯……复杂度在哪里?给自己找一个好的语法高亮编辑器,带有大括号匹配功能。试试notepad2。
'/(?<=:)"function(?:(?!}").)*}"/'
                 ^
                 +-- a "(" deleted