php - How change de eregi to preg_match in this code? -


if (preg_match('^'.preg_quote($this->config_document_root), $filename)) {       $absolutefilename = $filename;       $this->debugmessage('resolvefilenametoabsolute() not prepending $this->config_document_root ('.$this->config_document_root.') $filename ('.$filename.') resulting in ($absolutefilename = "'.$absolutefilename.'")', __file__, __line__);      } else {       $absolutefilename = $this->config_document_root.$filename;       $this->debugmessage('resolvefilenametoabsolute() prepending $this->config_document_root ('.$this->config_document_root.') $filename ('.$filename.') resulting in ($absolutefilename = "'.$absolutefilename.'")', __file__, __line__);      } } 

this code has been resolved instructions of first answer, how can fix code too?

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

solved, answers!

the question bit confusing because don't seem using eregi within posted code.

however, if want check if $filename starts $this->config_document_root don't need regular expression. e.g. why not use strpos?

if (strpos($filename, $this->config_document_root) === 0) { ... 

in regular expression ^ anchoring pattern start of text matched if rest of pattern simple text starts with check, second example written:

$docroot = str_replace(directory_separator, '/', realpath($this->config_document_root)); if (!$this->config_allow_src_above_docroot && strpos($filename, $docroot) !== 0) { ... 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -