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. :) Link to comment https://forums.phpfreaks.com/topic/13984-regular-expressions/ 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;?> Link to comment https://forums.phpfreaks.com/topic/13984-regular-expressions/#findComment-54569 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] Link to comment https://forums.phpfreaks.com/topic/13984-regular-expressions/#findComment-88419 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.