2

This is my code.

private function _checkMatch($modFilePath, $checkFilePath) {
        $modFilePath = str_replace('\\', '/', $modFilePath);
        $checkFilePath = str_replace('\\', '/', $checkFilePath);

        $modFilePath = preg_replace('/([^*]+)/e', 'preg_quote("$1", "~")', $modFilePath);
        $modFilePath = str_replace('*', '[^/]*', $modFilePath);
        $return = (bool) preg_match('~^' . $modFilePath . '$~', $checkFilePath);
        return $return;
}

I changed preg_replace to preg_replace_callback but it is giving me the following error.

Warning: preg_replace_callback(): Requires argument 2, 'preg_quote("$1", "~")', to be a valid callback

I'm currently using opencart version 1.x.x

Any one can help me out?

Ali Zia
  • 3,825
  • 5
  • 29
  • 77

1 Answers1

3

http://php.net/manual/en/function.preg-replace-callback.php

You need to use the valid callback as the second argument. You can use function or it name as string:

$modFilePath = preg_replace_callback('/[^*]+/', function ($matches){
    return preg_quote($matches[0], "~");
}, $modFilePath);

I have deleted unsecured e modifier and replaced it to a valid callback for preg_replace_callback function.

Also with Old version of PHP you need to add function statement below your code

function myCallback($matches){
    return preg_quote($matches[0], "~");
}

And then use preg_replace_callback('/[^*]+/', 'myCallback', $modFilePath);

Sfer23
  • 66
  • 3