erm ...我有一個類,試圖做一個模板類,使用preg_replace_callback,但我不知道參數2如何寫
class template {
public function parse_template($newtpl, $cachetpl){
......
$template = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}", $template);
$template = preg_replace_callback("/\{lang\s+(.+?)\}/is", $this->languagevar('\\1'), $template);
......
}
public function languagevar($param1){
......
return $lang[$param1];
......
}
}
這是如何工作的?在我的html(模板)文件中,有這樣的{lang hello},並且parse_template找到了{lang}它會使用$ this-> languagevar('hello')進行轉換的{lang}。
,但我一直在
$template = preg_replace_callback("/\{lang\s+(.+?)\}/is", $this->languagevar('\\1'), $template);
得到錯誤的錯誤消息是
preg_replace_callback():要求參數2, '(' \ 1 ')',是一個有效的 回調
之前,我可以做到用
回調但也許目前的PHP版本問題,遇到錯誤說/ E已被棄用,使用preg_replace_callback代替
我如何解析參數成languagevar('parameter'),參數從preg_replace(。+?) – user259752
@ user3040842獲取請閱讀'preg_replace_callback'手冊。你不能選擇你的回調會收到什麼樣的論據;它將傳遞一個*數組匹配模式*的數組。 – lafor