<?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));
$v = $($v);
var_dump($v);
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.4.17
- Parse error: syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$' in /in/aeII9 on line 11
Process exited with code 255. - Output for 5.3.0 - 5.3.27
- Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /in/aeII9 on line 11
Process exited with code 255.
preferences:
178.64 ms | 1395 KiB | 53 Q