替代功能preg_replace与e /修饰符

时间:2017-01-06 19:15:39

标签: php preg-replace

任何人都知道如何使用preg_replace和/ e修饰符更改此函数。我在调试时遇到了一个奇怪的错误,因为/ e modifier.Seems已被折旧。

$globCont = preg_replace("/{(\w*)}/e", '$this->TemplateGlobals["$1"]', $content);

1 个答案:

答案 0 :(得分:1)

使用匿名函数:

$globCont = preg_replace_callback("/{(\w*)}/", 
                                  function($m) {
                                      return $this->TemplateGlobals[$m[1]];
                                  }, $content);