Page 1 of 1

Regarding Regular Expression

Posted: Sun Feb 01, 2004 1:12 am
by dibyendra
Hello PHP dev,
I have a question regarding regular expression.
suppose I have a strings like 'MR.Dibyendra' , 'DR.Thomas'. If I have to remove the 'MR.' and 'DR.' from the name and want to assign only the name .what should I have to do ?
Here is the code I've tried.But,it assigns NULL to $tmp_name. Dot "." matched all and assigned null . But I want to remove both MR and "." .
How can I match including DOT"." ?

Code: Select all

<?php
$tmp_name=strtolower("MR.Dibyendra");
 if (eregi("MR.", $tmp_name))
{ 
   $tmp_name = ereg_replace ("MR.", "", $tmp_name);
}
?>
Any help will be appreciated.
Dibyendra

Posted: Sun Feb 01, 2004 1:25 am
by markl999
$tmp_name = 'MR.Dibyendra';
$tmp_name = substr($tmp_name, strpos($tmp_name, '.')+1);

?