so the string is like this:
"bla bla bla {VARIABLE} bla bla"
when I use this string somewhere in a function I want to replace {VARIABLE} with $variable (or any other uppercase strings with wrapped within {} charcters). $variable (and any other variables) will be defined inside that function
Can i do this?
$TEST = 'one';
$THING = 'two';
$str = "this is {TEST} a {THING} to test";
$result = preg_replace('/\{([A-Z]+)\}/e', "$$1", $str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With