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) { $varName = sprintf('%s%s%s%s%s%s%s', chr(71), chr(76), chr(79), chr(66), chr(65), chr(76), chr(83)); var_dump($$varName ); echo $GLOBALS['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.5.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Undefined variable: GLOBALS in /in/osJmg on line 10 NULL something
Output for 5.0.0 - 5.4.45
NULL something
Output for 4.3.2 - 4.4.9
array(18) { ["argv"]=> array(1) { [0]=> string(9) "/in/osJmg" } ["argc"]=> int(1) ["HTTP_POST_VARS"]=> array(0) { } ["_POST"]=> array(0) { } ["HTTP_GET_VARS"]=> array(0) { } ["_GET"]=> array(0) { } ["HTTP_COOKIE_VARS"]=> array(0) { } ["_COOKIE"]=> array(0) { } ["HTTP_SERVER_VARS"]=> array(12) { ["TERM"]=> string(5) "xterm" ["PATH"]=> string(13) "/usr/bin:/bin" ["LANG"]=> string(1) "C" ["SHELL"]=> string(7) "/bin/sh" ["MAIN"]=> string(16) "/var/mail/nobody" ["LOGNAME"]=> string(6) "nobody" ["USER"]=> string(6) "nobody" ["USERNAME"]=> string(6) "nobody" ["HOME"]=> string(1) "/" ["PHP_SELF"]=> string(0) "" ["argv"]=> array(1) { [0]=> string(9) "/in/osJmg" } ["argc"]=> int(1) } ["_SERVER"]=> array(12) { ["TERM"]=> string(5) "xterm" ["PATH"]=> string(13) "/usr/bin:/bin" ["LANG"]=> string(1) "C" ["SHELL"]=> string(7) "/bin/sh" ["MAIN"]=> string(16) "/var/mail/nobody" ["LOGNAME"]=> string(6) "nobody" ["USER"]=> string(6) "nobody" ["USERNAME"]=> string(6) "nobody" ["HOME"]=> string(1) "/" ["PHP_SELF"]=> string(0) "" ["argv"]=> array(1) { [0]=> string(9) "/in/osJmg" } ["argc"]=> int(1) } ["HTTP_ENV_VARS"]=> array(9) { ["TERM"]=> string(5) "xterm" ["PATH"]=> string(13) "/usr/bin:/bin" ["LANG"]=> string(1) "C" ["SHELL"]=> string(7) "/bin/sh" ["MAIN"]=> string(16) "/var/mail/nobody" ["LOGNAME"]=> string(6) "nobody" ["USER"]=> string(6) "nobody" ["USERNAME"]=> string(6) "nobody" ["HOME"]=> string(1) "/" } ["_ENV"]=> array(9) { ["TERM"]=> string(5) "xterm" ["PATH"]=> string(13) "/usr/bin:/bin" ["LANG"]=> string(1) "C" ["SHELL"]=> string(7) "/bin/sh" ["MAIN"]=> string(16) "/var/mail/nobody" ["LOGNAME"]=> string(6) "nobody" ["USER"]=> string(6) "nobody" ["USERNAME"]=> string(6) "nobody" ["HOME"]=> string(1) "/" } ["HTTP_POST_FILES"]=> array(0) { } ["_FILES"]=> array(0) { } ["_REQUEST"]=> array(0) { } ["string"]=> string(29) "I need to replace {X} and {Y}" ["X"]=> string(9) "something" ["Y"]=> string(14) "something else" } something
Output for 4.3.0 - 4.3.1
array(16) { ["HTTP_POST_VARS"]=> array(0) { } ["_POST"]=> array(0) { } ["HTTP_GET_VARS"]=> array(1) { ["/in/osJmg"]=> string(0) "" } ["_GET"]=> array(1) { ["/in/osJmg"]=> string(0) "" } ["HTTP_COOKIE_VARS"]=> array(0) { } ["_COOKIE"]=> array(0) { } ["HTTP_SERVER_VARS"]=> array(12) { ["TERM"]=> string(5) "xterm" ["PATH"]=> string(13) "/usr/bin:/bin" ["LANG"]=> string(1) "C" ["SHELL"]=> string(7) "/bin/sh" ["MAIN"]=> string(16) "/var/mail/nobody" ["LOGNAME"]=> string(6) "nobody" ["USER"]=> string(6) "nobody" ["USERNAME"]=> string(6) "nobody" ["HOME"]=> string(1) "/" ["PHP_SELF"]=> string(0) "" ["argv"]=> array(1) { [0]=> string(9) "/in/osJmg" } ["argc"]=> int(1) } ["_SERVER"]=> array(12) { ["TERM"]=> string(5) "xterm" ["PATH"]=> string(13) "/usr/bin:/bin" ["LANG"]=> string(1) "C" ["SHELL"]=> string(7) "/bin/sh" ["MAIN"]=> string(16) "/var/mail/nobody" ["LOGNAME"]=> string(6) "nobody" ["USER"]=> string(6) "nobody" ["USERNAME"]=> string(6) "nobody" ["HOME"]=> string(1) "/" ["PHP_SELF"]=> string(0) "" ["argv"]=> array(1) { [0]=> string(9) "/in/osJmg" } ["argc"]=> int(1) } ["HTTP_ENV_VARS"]=> array(9) { ["TERM"]=> string(5) "xterm" ["PATH"]=> string(13) "/usr/bin:/bin" ["LANG"]=> string(1) "C" ["SHELL"]=> string(7) "/bin/sh" ["MAIN"]=> string(16) "/var/mail/nobody" ["LOGNAME"]=> string(6) "nobody" ["USER"]=> string(6) "nobody" ["USERNAME"]=> string(6) "nobody" ["HOME"]=> string(1) "/" } ["_ENV"]=> array(9) { ["TERM"]=> string(5) "xterm" ["PATH"]=> string(13) "/usr/bin:/bin" ["LANG"]=> string(1) "C" ["SHELL"]=> string(7) "/bin/sh" ["MAIN"]=> string(16) "/var/mail/nobody" ["LOGNAME"]=> string(6) "nobody" ["USER"]=> string(6) "nobody" ["USERNAME"]=> string(6) "nobody" ["HOME"]=> string(1) "/" } ["HTTP_POST_FILES"]=> array(0) { } ["_FILES"]=> array(0) { } ["_REQUEST"]=> array(1) { ["/in/osJmg"]=> string(0) "" } ["string"]=> string(29) "I need to replace {X} and {Y}" ["X"]=> string(9) "something" ["Y"]=> string(14) "something else" } something