Regarding Regular Expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dibyendra
Forum Newbie
Posts: 20
Joined: Tue Aug 12, 2003 2:26 am
Location: Nepal

Regarding Regular Expression

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$tmp_name = 'MR.Dibyendra';
$tmp_name = substr($tmp_name, strpos($tmp_name, '.')+1);

?
Post Reply