Jump to content

Regular Expressions


skerg

Recommended Posts

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

<?

//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

  • 2 months later...
[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 => Center
CENTER => Center
CeNtEr => Center
cntr => Center
ctr => Center
CTr => Center
g+a-r1bag#e => g+a-r1bag#e
string with ctr => string with Center
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/13984-regular-expressions/#findComment-88419
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.