3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = "I need to replace {X} and {Y}"; $X = 'something'; $Y = 'something else'; function parse($string) { $v = sprintf('%s%s%s%s%s%s%s', chr(71), chr(76), chr(79), chr(66), chr(65), chr(76), chr(83)); echo $v['X']; return; preg_match_all('/\{(.*?)\}/', $string, $matches); foreach ($matches[1] as $value) { $string = str_replace('{'.$value.'}', ${$value}, $string); } return $string; } echo parse($string);
Output for 5.4.0 - 5.6.28, 7.0.0 - 7.1.0
Warning: Illegal string offset 'X' in /in/iP7of on line 11 G
Output for 4.3.0 - 5.3.29, hhvm-3.10.0 - 3.12.0
G