need help with preg_match

Discussion in 'PHP' started by phantom, Jan 10, 2009.

  1. #1
    can anyone tell me how to match only letters numbers and dots and that it?


    I tried doing this with ereg ereg("^[a-zA-Z0-9\-]+\.") but can't get it to work.

    any ideas?
     
    phantom, Jan 10, 2009 IP
  2. phantom

    phantom Well-Known Member

    Messages:
    1,509
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    140
    #2
    nevermind I figured it out!
     
    phantom, Jan 10, 2009 IP
  3. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #3
    You could also try this regex: (\w(\s)?)+ :) It's a bit shorter
     
    elias_sorensen, Jan 11, 2009 IP
  4. MRPK

    MRPK Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    preg_mathc_all("/[0-9a-zA-Z\.]/+",$string,$match_arr);
     
    MRPK, Jan 11, 2009 IP
  5. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #5
    It is preg_match_all ;) And if he just want a false or true return of the function (e.g. in an if statement), he should use eregi ;)
     
    elias_sorensen, Jan 11, 2009 IP
  6. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #6
    No he shouldn't, The ereg features are being removed from the default PHP installation in PHP 6. You should avoid them in place of the PCRE functions.

    Dan.
     
    Danltn, Jan 12, 2009 IP