I have a string that is like this
{{ some text @ other text @ and some other text }} @ this should not be replaced {{ but this should: @ }}
I want it to become
{{ some text ### other text ### and some other text }} @ this should not be replaced {{ but this should: ### }}
I guess the example is straight forward enough and I’m not sure I can better explain what I want to to achieve in words.
I tried several different approaches but none worked.
This can be achieved with a regular expression calling back to a simple string replace:
I have opted for a simple non-greedy regular expression to find your braces but you may choose to alter this for performance or to suit your needs.
Anonymous functions would allow you to parameterise your replacements:
Documentation: http://php.net/manual/en/function.preg-replace-callback.php