3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MicroTemplateEngine { public $data = array(); private $tpl; function __construct($f) { $this->tpl = $f; } function __set($name, $value) { $this->data[$name] = $value; } function __toString() { $out = $this->tpl; foreach ($this->data as $_key => $_value) { $out = str_replace('#{{' . $_key . '}}', $_value, $out); } $out = preg_replace('/#{{.*?}}/' , '' , $out ); return $out; } } $t = new MicroTemplateEngine('<#{{element}} id="element-#{{id}}">#{{inner}}</#{{element}}>'); $t->data = (object)array('element'=> 'span', 'id'=>45, 'inner' => 'Teste templating engine!'); var_dump($t); echo $t;

preferences:
31.36 ms | 402 KiB | 5 Q