Stripping out value from submited data

Discussion in 'PHP' started by amelen, Aug 18, 2009.

  1. #1
    Quick php question for the experts out there.

    We have a form which users are filling out. They should be just submitting a username into the form, so for example "myusername" would be a value. BUT some are somehow submitting "www.myusername". Many claim that their browser pre-fills this. We have been displaying an error when this happens, but many continue to ignore it.

    How can we check on the back end if the username submitted has "www." in it, and strip it out if it does (before doing anything with the username like submitting it to the database).
     
    amelen, Aug 18, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $username = str_replace('www.', '', $username);
     
    kblessinggr, Aug 18, 2009 IP
  3. amelen

    amelen Active Member

    Messages:
    686
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    85
    #3
    wow.. that's pretty easy :).. thanks!

    So what happens if the username doesn't have www.? It just doesn't remove anything?
     
    amelen, Aug 18, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    See http://php.net/str_replace :

    So yes, it doesn't remove anything if it's not in there. You may also be interested in str_ireplace to do a case insensitive replace.
     
    premiumscripts, Aug 18, 2009 IP