How to solve Preg_match warning? [duplicate]

别来无恙 提交于 2019-12-25 04:26:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!