Preg_match上的语法

时间:2017-03-08 14:14:41

标签: php mysql

我正在交换一个已有几年历史的程序,并更新了PHP和MySQL的修复程序,并且我对preg_matchereg的语法进行了混淆。我尝试在任何地方插入斜杠,但无法提出正确的语法。我错过了什么?

Old Line:

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

新行:

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

请原谅我的新手,我是否需要逃避' /'?

1 个答案:

答案 0 :(得分:1)

您缺少preg_*函数所需的分隔符:

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

当我使用#时,没有必要逃避正斜杠。

相关问题