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

2 番目の引数として有効なコールバックを使用する必要があります。関数またはその名前を文字列として使用できます。

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

セキュリティで保護されていない修飾子を削除し、関数eの有効なコールバックに置き換えました。preg_replace_callback

また、PHPの古いバージョンでは、コードの下に関数ステートメントを追加する必要があります

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

そして、使用しますpreg_replace_callback('/[^*]+/', 'myCallback', $modFilePath);

于 2015-11-05T11:47:11.503 に答える