问题
I am using preg_match function in my program. The code is like this
if (!$this->config_allow_src_above_docroot && !preg_match('^'.preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', realpath($this->config_document_root))), $AbsoluteFilename))
But run the application it shows the warning like this
Warning: preg_match() [function.preg-match]: No ending delimiter '^'
Can you help me please..
回答1:
You must add pattern delimiters:
preg_match('/^' . preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', realpath($this->config_document_root))) . '/', $AbsoluteFilename)
^ ^
Since you have forgotten to put delimiters in your pattern, the regex engine believes that ^
is the starting delimiter and is surprised to not found the same delimiter at the end of the pattern.
来源:https://stackoverflow.com/questions/21339492/how-to-solve-preg-match-warning