Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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解析错误:函数中的语法错误_Php_Preg Replace - Fatal编程技术网

Php preg_replace解析错误:函数中的语法错误

Php preg_replace解析错误:函数中的语法错误,php,preg-replace,Php,Preg Replace,我正在尝试将GeSHi语法highlighter集成到我的博客中 我的代码中出现语法错误。我对PHP代码不是很在行,因此在纠正语法方面寻求帮助 我的代码是: private function _renderCode($string) { return preg_replace('/<listing (.*?)>(.*?)</listing>/es', '$this->highlightString('\2', '\1')',

我正在尝试将GeSHi语法highlighter集成到我的博客中

我的代码中出现语法错误。我对PHP代码不是很在行,因此在纠正语法方面寻求帮助

我的代码是:

private function _renderCode($string)
{
    return preg_replace('/<listing (.*?)>(.*?)</listing>/es',
                '$this->highlightString('\2', '\1')', 
                $string);
}
Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR)

查看突出显示的语法:

'$this->highlightString('\2', '\1')'
您需要在单引号字符串中转义单引号

'$this->highlightString(\'\2\', \'\1\')'

(顺便说一句,首选的形式是
'$this->highlightString(\'$2\',\'$1\')

试试
'$this->highlightString(\'\\2\',\'\\1\'),