For some reason preg_replace
is not working when the substitution includes curly braces {}
.
If the original line is:
$Original_Line = "new_Journey('Iceland', {character: 'lidenbrock'}, {author : 'verne', destination : 'snæfellsjökull'})";
and the substitution (after pattern matching) is:
new_Journey('$1', [$3, $2])
giving the following pattern-match/substitution:
$Replacement_Line = preg_replace("/new_Journey\(\'([^\']+)\'\,\s*\{([^\}]+)\}\,\s*\{([^\}]+)\}\)\;/", "new_Journey('$1', [$3, $2])", $Original_Line);
the output is correct (albeit with square brackets []
instead of curly braces {}
):
new_Journey('Iceland', [author : 'verne', destination : 'snæfellsjökull', character: 'lidenbrock']);
But if the substution uses curly braces {}
instead of square brackets []
like this:
new_Journey('$1', {$3, $2})
the output is an error:
Parse error: syntax error, unexpected '3' (T_LNUMBER), expecting variable (T_VARIABLE) or '{' or '$' in [...][...] on line 5
Should I be escaping the curly braces {}
in the substitution? If so, how?