SL0WLearner
SL0WLearner

Reputation: 29

Syntax on Preg_match

I'm swapping a program out that is several years old, and updating the PHP, and MySQL deprication, and am getting jammed up on syntax for preg_match versus ereg. I tried putting slashes everywhere, and cannot come up with the correct syntax. What am I missing?

Old Line:

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

New Line:

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

Please excuse my newb-ness, do I need to escape the '/'?

Upvotes: 0

Views: 40

Answers (1)

jeroen
jeroen

Reputation: 91744

You are missing the delimiters that are required for the preg_* functions:

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

As I am using the #, there is no need to escape the forward slash.

Upvotes: 1

Related Questions