preg_replace match, works with string functions?
Moderator: General Moderators
Re: preg_replace match, works with string functions?
I think you need to use preg_replace_callback if you want to use a function to handle the replacement.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: preg_replace match, works with string functions?
Also, the reason your first version didn't work was because you need to wrap the replacement code inside a string so that PHP can eval() it.
I'm not 100% but you may need to use $1 in this specific scenario (where you're using the "e" modifier) too. I seem to remember that being the case, but logically I can't see why.
Code: Select all
$test = 'Hello <B>THERE<I>';
$test = preg_replace('/.*?\.*?/e', "return strtolower('\\1');", $test);