www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] preg_replace question

  1. #1
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582

    resolved [RESOLVED] preg_replace question

    Hello, everyone.

    I'm working on a user registration page for a personal project (a labor of love, heh) and am having a bit of an issue with preg_replace.

    Basically, I have a Stored Procedure that will first check to see if a user has already registered. Primarily it checks first and last name; if the name doesn't yet exist in the database, then it checks email address; if there is not already a record in the database with that name OR email address, it inserts the data.

    As far as the name check, I am sending the first and last name TWICE - first as the user entered it, then also I want to send the first and last name but replacing any spaces, apostrophes, or hyphens with the "%" wildcard (ie, if the user enters a first name of "La-Jenna", "La Jenna", or "La'Jenna", the search string will be "La%Jenna".)

    But the preg_replace is not swapping out spaces, apostrophes, or hyphens. Here is my replace code:
    Code:
    $fNameCompare = preg_replace("/ '-/i","%",$_POST['firstName']);
    $lNameCompare = preg_replace("/ '-/i","%",$_POST['lastName']);
    If I enter "John-Paul" and echo $fNameCompare on submit, it shows as "John-Paul", not "John%Paul". What am I doing incorrectly?

    Thanks,
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    I'm guessing what you actually want for your regexp is:
    Code:
    "/[ '-]/i"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Thanks, NogDog.. I'll give that a shot next time I have my server up and running.
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

  4. #4
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    That was it! Thanks, NogDog!
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles