2015-11-05 61 views
2

这是我的代码。替换preg_replace_callback的preg_replace给我一个警告

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.x.x

任何一个可以帮助我吗?

回答

2

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

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

$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);

+0

三江源这么多! –