"\s*", "+" => "\s+", ":var" => "(\w+(\s*\.\s*\w+)*)", ":id" => "(\w+)"]); return ["/$body/", function ($x) use ($result) { return ""; }]; }, [ ["{% for+:id+in+:var %}", "foreach(\$#2 as \$index => \$#1): \$loop = Klein::loop(\$index, \$#2);"], ["{% for+:id , :id+in+:var %}", "foreach(\$#3 as \$#1 => \$#2):"], ["{% endfor %}", "endforeach;"], ["{% if+:var %}", "if(isset(\$#1) && \$#1 ):"], ["{% endif %}", "endif;"], ["{{ :var }}", "echo \$#1;"], ["{{ :var\|:id }}", "echo #3(\$#1);"] ]); $result = file_get_contents($html); foreach($pattern as $arg) { $result = preg_replace_callback($arg[0], $arg[1], $result); } $this->code = $result; } static function loop($idx, &$array) { $is_even = $idx % 2; return ['first' => $idx == 0 , 'last' => $idx == count($array) - 1 , 'odd' => !$is_even , 'even' => $is_even]; } function render($vars) { extract($vars); ob_start(); eval(" ?>".$this->code."