View Full Version : preg_match & ereg_replace help

05-04-2004, 10:48 PM
Hello all... I'm having an issue..

I have a form that gives me some variables for insertion into a mysql database... Sometimes the people use "Dr" or "Dr " or "dr" or "Dr. " and you get the hint...

I have a variable

I want to use
preg_match() to find out if there is even a variance of the above within the string... If there is, I'd like to replace it (leaving the actual name... for instance... user enters dr Rich..) I'd like to replace it with Dr. Rich (note the space) with
ereg_replace() ... Is this possible and how can I do it very simply?


05-04-2004, 11:46 PM
i prefer preg_replace:

$first = preg_replace("/dr\.? /i", "Dr. ",$_REQUEST['first']);

looks for an case variant of 'dr' with optional period following, and a space. replaces with 'Dr. '

you might be able to avoid all this, by having the user select a title with an <SELECT> HTML tag.