Php regular expression replacement $ array = array ('AAA', 'bbbbbbbb', 'cccccccccc', 'ddddddddddd ');
$ Str = 'abcdej {$ array} jdijij ';
$ Str = preg_replace ("/^ \{\$ (.*?) \} $/I ", 'print _ r (\ 1); ', $ str );
Print_r ($ str );
How to replace the regular expression with {print_r ($ array ??
How do I write regular expressions such as for while foreach ???
Reply to discussion (solution)
$ Str = 'abcdej {$ array} jdijij '; $ str = preg_replace ('/\ {(\ $. + ?) \}/','
', $ Str); echo $ str;
Abcdej Jdijij
When the rule string is enclosed in double quotation marks
$ Str = 'abcdej {$ array} jdijij'; $ str = preg_replace ("// \{ (\\\$. + ?) \}/",'
', $ Str); echo $ str;
The results of \\$ and \\\$ are the same. I know that \ is an escape, but only two are allowed. but in many places, three are written. why?
This is a test result. for example, you have to write three in my environment.