skerg Posted July 7, 2006 Share Posted July 7, 2006 Hey guys, I've started to play with some regular expressions but for the life of me I can't figure out the correct syntax for this. I need a regex that can find different versions of the word Center. For example I need to be able to change Ctr and Cntr into Center. I can't seem to figure out how to do it, if anyone can help me out I'd be very thankfull. :) Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 7, 2006 Share Posted July 7, 2006 <?//This is erigi replace with no array.$a="Cnt";$b ="center";$replace=eregi_replace($a,"",$b);echo $replace;?> <?//This is eregi with array$a=array("Cnt");$b=array("center");$replace=eregi_replace($a[0],"",$b[0]);echo $replace;?><?//This is str_replace with no array.$a="Cnt";$b ="center";$replace=str_replace($a,"",$b);echo $replace;?> <?//This is str_replace with array$a=array("Cnt");$b=array("center");$replace=str_replace($a[0],"",$b[0]);echo $replace;?> Quote Link to comment Share on other sites More sharing options...
effigy Posted September 8, 2006 Share Posted September 8, 2006 [code]<pre><?php $tests = array( 'center', 'CENTER', 'CeNtEr', 'cntr', 'ctr', 'CTr', 'g+a-r1bag#e', 'string with ctr', ); foreach ($tests as $test) { echo "$test => "; echo preg_replace('/ce?n?te?r/i', 'Center', $test); echo '<br/>'; }?></pre>[/code][quote]center => CenterCENTER => CenterCeNtEr => Centercntr => Centerctr => CenterCTr => Centerg+a-r1bag#e => g+a-r1bag#estring with ctr => string with Center[/quote] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.