开发者

Transform ereg_replace to preg_replace

开发者 https://www.devze.com 2023-04-05 20:12 出处:网络
can someone transform this ereg_replace expression to preg_replace? $string = mb_ereg_replace(\'([ -\\.,\\+\\?\\(\\)\\$\\[\\];_=])\'

can someone transform this ereg_replace expression to preg_replace?

$string = mb_ereg_replace('([ -\.,\+\?\(\)\$\[\];_=])'
                         .$oldvalue.'([ -\.,\+\?\(\)\$\[\];_=])',"\\1"  
                         .$newvalue."\\2",$string);

Basically it searches a string ($oldvalue) which is preceded by space or dash or fullstop or plus sign开发者_Python百科 or parenthesis or brackets or question-mark or equal sign and is followed by one of these too and transforms it to (whatever was preceding)$newvalue(whatever was following).

I need to switch to preg_replace due to technical limitations, I hope someone can help!

Thank you!


$string = preg_replace('([ -\.,\+\?\(\)\$\[\];_=])' 
                     .$oldvalue.'([ -\.,\+\?\(\)\$\[\];_=])',"$1"   
                     .$newvalue."$2",$string); 

Done.

0

精彩评论

暂无评论...
验证码 换一张
取 消