10 private function _build_replace($r, $prefix){
12 if(is_array($r) && count($r)) {
13 foreach ($r as $k => $v ) {
15 $this->_build_replace($v, "$prefix$k.");
17 $this->search[] = $prefix . $k;
18 $this->replace[] = $v;
23 private function _replcb_if($m){
24 //echo "<pre>"; var_dump($m);
25 $keys = explode(".",$m[1]);
27 foreach($keys as $k) {
32 return ($val?$m[2]:"");
35 public function replace($s, $r) {
38 $this->search = array();
39 $this->replace = array();
41 $this->_build_replace($r, "");
44 $s = preg_replace_callback("|{{ *if *([^ }]*) *}}([^{]*){{ *endif *}}|", array($this, "_replcb_if"), $s);
46 return str_replace($this->search,$this->replace,$s);