Hello.
I need some help with basic PHP regular expressions.
Basically, I want to find a string within a string and replace it.
e.g. Find "abc*def" (where * is a wildcard) and replace with "cba*fed" (where * is the same wildcard).
I only want the replacement to happen if "abc" precedes "def" somewhere in the string. str_replace() doesn't support it, as far as I know.
How else can I do it?
Thank you in advance, hoping to get some good replies.
$string = 'thisabcdunnodefmememe';
$pattern = '/^(.*)abc(.*)def(.*)$/i';
$replacement = '$1cba$2fed$3';
echo preg_replace($pattern, $replacement, $string);
Should give you 'thiscbadunnofedmememe'. I didn't test it but should be correct.
If wrong, well... too bad.