currently i have the following situation: I'm trying to "parse" a text, looking for placeholders (their notation is "{...}") and later on, i will replace them with the actual text.
I thought about regular expressions
$foo = "Hello World {foo{bar}} World Hello!";
$bar = array();
preg_match_all('@\{.+\}@U', $foo, $bar);
var_dump($bar);
But this returns
array(1) { [0]=> array(1) { [0]=> string(9) "{foo{bar}" } }
Making it greedy will result in:
array(1) { [0]=> array(1) { [0]=> string(10) "{foo{bar}}" } }
But i want the result to be something like:
array(1) { [0]=> array(2) { [0]=> string(5) "{bar}" [1]=> string(10) "{foo{bar}}" } }
Is there a way to reach this with the help of preg_match(_all) and regular expressions?
Or do i have to loop over my $bar again and again, until there are no sub-statements left in the result set?