PHP Strip/Remove period

Discussion in 'PHP' started by MakeThatDollar, Aug 5, 2008.

  1. #1
    I have the following variable:

    $domain[domain]

    Which would equal something such as:

    thisismydomain.com

    I want it to strip/remove the period so it returns the following instead:

    thisismydomaincom

    Can someone help?
     
    MakeThatDollar, Aug 5, 2008 IP
  2. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #2
    use this

    $dom = ereg_replace('.', '', $domain[domain]);
     
    olddocks, Aug 5, 2008 IP
    MakeThatDollar likes this.
  3. MakeThatDollar

    MakeThatDollar Notable Member

    Messages:
    4,451
    Likes Received:
    158
    Best Answers:
    0
    Trophy Points:
    225
    #3
    For some reason that's not working.

    Any other ways it can be done?

    EDIT: Actually, by changing ereg_replace to str_replace, it worked fine.

    Thanks, +rep!
     
    MakeThatDollar, Aug 5, 2008 IP
  4. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #4
    I know you got it to work but let me tell you what you did wrong...

    "." means every possible character, so you (ereg_)replaced all the characters of the domain name to '' and got an empty string at the end.

    This could have worked but is not the best choise since str functions are faster than ereg ones:

    $dom = ereg_replace('\.', '', $domain[domain]); 
    // see the backslach before the wildcart dot to cancel it special meening
    PHP:
     
    nabil_kadimi, Aug 5, 2008 IP
  5. reubix90

    reubix90 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ^ That looks right or just parse out the whole '.com' on the variable
     
    reubix90, Aug 5, 2008 IP
  6. MakeThatDollar

    MakeThatDollar Notable Member

    Messages:
    4,451
    Likes Received:
    158
    Best Answers:
    0
    Trophy Points:
    225
    #6
    Not all domains have .com. Some are .net, .org, .us, etc... :)
     
    MakeThatDollar, Aug 6, 2008 IP
  7. BMR777

    BMR777 Well-Known Member

    Messages:
    145
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    140
    #7
    $domain = preg_replace("/[^a-zA-Z0-9_-]/", "", $domain);
    PHP:
    :)
     
    BMR777, Aug 6, 2008 IP