Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    preg_match & ereg_replace help

    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
    PHP Code:
    $_REQUEST['first'
    ...

    I want to use
    PHP Code:
    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
    PHP Code:
    ereg_replace() 
    ... Is this possible and how can I do it very simply?

    Thanks,
    Rich
    Rich S. Wyatt
    D3 Web Creations

  • #2
    Regular Coder dswimboy's Avatar
    Join Date
    Nov 2003
    Location
    mostly in Ann Arbor
    Posts
    458
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i prefer preg_replace:

    PHP Code:
    $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.
    "There is more than one way to do it."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •