3v4l.org

run code in 300+ PHP versions simultaneously
<?php function template($template, $vals) { $matches = array(); $regex = "/\{\{(\S+)\}\}/e"; $rendered = $template; // in case no matches are found preg_match_all($regex, $template, $matches, PREG_OFFSET_CAPTURE, 3); foreach ($matches[0] as $found) { $block = $found[0]; $offset = $found[0]; $k = str_replace('{{', '', $block); $k = str_replace('}-}', '', $k); $rendered = preg_replace($regex, '$vals[\\1]', $template); } return $rendered; } function template2($template, $vals) { $matches = array(); $regex = "/\{\{(\S+)\}\}"; $rendered = $template; // in case no matches are found preg_match_all($regex, $template, $matches, PREG_OFFSET_CAPTURE, 3); foreach ($matches[0] as $found) { $block = $found[0]; $offset = $found[0]; $k = str_replace('{{', '', $block); $k = str_replace('}-}', '', $k); $rendered = preg_replace_callback($regex, function($matches) { return $matches[0]; }, $template); } return $rendered; } $template = "test {{ME}}."; $vals = array('ME' => 'beep'); echo template2($template, $vals);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: preg_match_all(): No ending delimiter '/' found in /in/BcZDq on line 30 Warning: Undefined array key 0 in /in/BcZDq on line 32 Warning: foreach() argument must be of type array|object, null given in /in/BcZDq on line 32 test {{ME}}.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
52.69 ms | 401 KiB | 8 Q