2

这是我的代码。

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;
}

我将 preg_replace 更改为 preg_replace_callback 但它给了我以下错误。

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

我目前正在使用 opencart 版本 1.xx

任何人都可以帮助我吗?

4

1 回答 1

3

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

您需要使用有效的回调作为第二个参数。您可以使用函数或它的名称作为字符串:

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

我已删除 unsecurede修饰符并将其替换为有效的preg_replace_callback函数回调。

同样对于旧版本的 PHP,您需要在代码下方添加函数语句

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

然后使用preg_replace_callback('/[^*]+/', 'myCallback', $modFilePath);

于 2015-11-05T11:47:11.503 回答