3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php const ERRMODE_EMPTY = 1; const ERRMODE_LITERAL = 2; const ERRMODE_EXCEPTION = 3; function render_template($template, array $variables, $escapeChar = '@', $errMode = ERRMODE_EXCEPTION) { $esc = preg_quote($escapeChar); $expr = "/ $esc$esc(?=$esc*+{) | $esc{ | {(\w+)} /x"; $callback = function($match) use($variables, $escapeChar, $errMode) { switch ($match[0]) { case $escapeChar . $escapeChar: return $escapeChar; case $escapeChar . '{': return '{'; default: if ($errMode === ERRMODE_EMPTY) { return ''; } else if ($errMode === ERRMODE_LITERAL) { return $match[0]; } else if ($errMode === ERRMODE_EXCEPTION) { throw new \Exception('Unknown placeholder: ' . $match[1]); } else { return $errMode; } } }; return preg_replace_callback($expr, $callback, $template); } $template = <<<'TPL' HELLO {name} How are you doing {when} Feeling @{ok}? TPL; $data = [ 'name' => 'WORLD', 'when' => 'yesterday', ] echo render_template($template, $data);
based on 1hDoH
Output for 5.4.0 - 5.4.34
Parse error: syntax error, unexpected 'echo' (T_ECHO) in /in/XENqu on line 50
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/XENqu on line 45
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_CONST in /in/XENqu on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_CONST in /in/XENqu on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/XENqu on line 3
Process exited with code 255.