2014-01-24 143 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) 
      ^                        ^

由於您忘記了將分隔符放在您的模式中,正則引擎相信^是起始分隔符,並且驚奇地發現模式末尾沒有相同的分隔符。