Lets say I have:
$line = "{This is my {sentence|words} I wrote.}"
Output:
This is my sentence I wrote.
This is my words I wrote.
But, the regex should match deep and nested values and split these values, for example:
$line = "{This is my {sentence|words} I wrote on a {sunny|cold} day.}";
Output:
This is my sentence I wrote on a sunny day.
This is my sentence I wrote on a cold day.
This is my words I wrote on a sunny day.
This is my words I wrote on a cold day.
My first though was doing it over explode as in code below, but the result was not appropriate:
$res = explode("|", $line);
Advices? Thank you.
EDIT: Something in these lines:
$line = "{This is my {sentence|words} I wrote on a {sunny|cold} day.}";
$regex = "{[^{}]*}";
$match = [];
preg_match($regex, $line, $match);
var_dump($match);
As already said, it can go to an infinite so no limit, something in a for-loop appropriate.
/{[^{}]*}/
and returns the match and its index... Then, while the return is not -1, you keep exploding by|
... Of course you will need an array to push each new sentence (composed by one of the exploded values inserted in the index returned by the function) – Ishmaelite$line = "{This is my {sentence|words} I wrote on a {{very|not so} sunny|{freezing|rather} cold} day.}";
– Monroy