I want to replace { by {{} and } by {}}, because, I need to escape those { & } with {}.
if I’ve as input {blah} I want my script to output {{}blah{}}, see?
But it is not working look at what I did
$output = str_replace(array("}", "{"), array("{}}", "{{}"), '{blah}');
But as output I got this : {{}blah{{}}} instead of {{}blah{}}
PHP iterates the whole string for each array item you put in the $search parameter.
It is in fact replacing
'{blah}'into'{blah{}}'with your first array item'{', and then from that into'{{}blah{{}}}'because there is another'{'after the first replacement.You better off doing this with regular expression, with a single RegExp pattern it will run only once in your input string.