2014-01-24 145 views
0

我在我的程序中使用了preg_match函数。该代码是这样的如何解决Preg_match警告?

if (!$this->config_allow_src_above_docroot && !preg_match('^'.preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', realpath($this->config_document_root))), $AbsoluteFilename)) 

但运行应用程序它显示了这样的警告

Warning: preg_match() [function.preg-match]: No ending delimiter '^' 

你能不能帮我请..

回答

0

您必须添加模式分隔符:

preg_match('/^' . preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', realpath($this->config_document_root))) . '/', $AbsoluteFilename) 
      ^                        ^

由于您忘记了将分隔符放在您的模式中,正则引擎相信^是起始分隔符,并且惊奇地发现模式末尾没有相同的分隔符。