2015-11-05 63 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

三江源這麼多! –