<?php
function render($t,$v=null){
function _rh(&$f,&$v) {
static $m;$m?:$m=array();
if(isset($m[$f])) return $m[$f];
for($t=strtok($f,'.'),$q=isset($v[$t])?$v:'';
isset($q[$t])&&$t!==false;
$q=isset($q[$t])?$q[$t]:'',$t=strtok('.')
); return $m[$f]=($t?'':$q);
}
$t = is_array($t)?'':$t; if(empty($v)) return $t;
for ($e=explode('{{',$t),$r=$e[$i=0];
isset($e[++$i]) && $ss=explode('}}',$e[$i]);
$r.=(strpos($q=trim($ss[0]),'.')!==false?
_rh($q,$v):(isset($v[$q])?$v[$q]:''))
.end($ss));return $r;
}
echo render('My name is {{name}}, I\'m {{job.role}} at {{job.info.agency}}, {{job.place}}. [{{job.info.url}}].',[
'name' => 'Stefano',
'job' => [
'role' => 'CTO',
'place' => 'Italy',
'info' => [
'agency' => 'Caffeina',
'url' => 'http://caffeina.co',
],
],
]);
- Output for 5.4.0 - 5.4.32
- Parse error: syntax error, unexpected ' ' (T_STRING) in /in/MiveP on line 3
Process exited with code 255. - Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected T_STRING in /in/MiveP on line 3
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_STRING in /in/MiveP on line 3
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/MiveP on line 3
Process exited with code 255.
preferences:
210.79 ms | 1395 KiB | 123 Q