Working on a personal project I am using PHP and I'd like to run a preg_replace_callback
function against the following strings:
1. {{hello}}
2. {{hello}{there}{how}{are}{you}}
I'd like to detect the hello
there
how
are
and you
and send to a function as $matches[0-4]
(or however many there may be, needs to be variable from 1 to infinity).
The above isn't too hard for me, but i'd also like it so if I pass this string :
3. {{hello}{there}{how}{are}{you}} blabla {{I}{Am}{Fine}{Thanks for asking}}
The function I send the $matches[0-X]
to should be run TWICE, as the the little {{}} system I designed is opened and shut twice!
The pattern should also ignore {text just on its own like this} and BUT SHOULD run for {{text like this, i.e. just one box}}.
If I can type things with a back slash as a condition, such as:
4. {{ignore this next closing curly bracket \} as the slash makes it text}
...And it also could then also remove that now un-required backslash... well... THAT WOULD GET MASSIVE BONUS POINTS!!
All this is a preg_replace_callback
too so I need the entire {{thing}{here}} to be replaced by whatever the function returns.
Is this simple? Or hard? I'm stuck!
Love learning though so if anyone could help me, it would be more appreciated than you'd ever imagine. Thank you!
EDIT p.s. If it is just too hard to do as I explain above, i'd accept it working for something like:
[{hello}{there}{how}{are}{you}]
Using square brackets as well as curly - But that is much less desirable...