Preg_match behaviour

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BWGames

    Preg_match behaviour

    Can someone tell me if this is the correct way to go about it, or if
    there's a better way?

    Need to detect if a variable is a email address or not. The only time @
    would ever occur in that variable is if its an email:

    So, whats wrong with:

    if (preg_match("/@/", "$to")) {
    $email =1;
    }

    Thanks,

    Ben
    --
    BWGames
    to email change de.news to de-news
  • Daniel Tryba

    #2
    Re: Preg_match behaviour

    BWGames <de.news@bwgame s.net> wrote:[color=blue]
    > Need to detect if a variable is a email address or not. The only time @
    > would ever occur in that variable is if its an email:
    >
    > So, whats wrong with:
    >
    > if (preg_match("/@/", "$to")) {
    > $email =1;
    > }[/color]

    Not much, it's only a useless use of regexps. strpos('@',$to) !==false
    would be a better replacement.

    --

    Daniel Tryba

    Comment

    Working...