I\'m having a problem using a variable from preg_replace. Basically what I want to achieve is to look for some patterns in a text, and replace them by content. The replacement i
The problem is that $this->retrieveValue($templateVars,'$1')
is executed before you call preg_replace
.
Solution: Have a look at preg_replace_callback.
I suggest you create a new method in your class:
public function _replace($matches) {
return $this->retrieveValue($templateVars, $matches[1]);
}
and then can use:
preg_replace_callback('/\*#(.*?)#\*/', array($this, '_replace'), $template);
You can also make use of anonymous functions in PHP 5.3.