This question already has an answer here:
I was using ereg_replace function to replace all tags in my HTML with blank. Tags in my case look like this: {{AGE}} {{NAME}} {{EMAIL_ADDRESS}}
I was using this sentence (was removed in PHP 7):
$my_string = ereg_replace("\{\{[a-zA-Z_0-9]+\}\}", "", $my_string);
Now I would like to use alternative sentence to ereg_replace and I tried with this:
$my_string = preg_replace("\{\{[a-zA-Z_0-9]+\}\}", "", $my_string);
It throws out error. Looks like 1st parameter for preg is not same as for ereg. Can someone tell me how to fix it to replace all tags which have format {{something here}}
Thanks.
</div>
With preg_*
-functions, your expressions require a delimiter (some character at the beginning and end of your expression that tells the underlying engine where your expression ends and any optional modifiers begin).
Most developers use /
for a delimiter, so:
$my_string = preg_replace("/\{\{[a-zA-Z_0-9]+\}\}/", "", $my_string);
Although I don't think the {
and }
characters have special meaning in regular expressions, so you might be able to get away with not escaping them:
$my_string = preg_replace("/{{[a-zA-Z_0-9]+}}/", "", $my_string);