By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,635 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,635 IT Pros & Developers. It's quick & easy.

Preg_match behaviour

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
BWGames <de*****@bwgames.net> wrote:
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;
}


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

--

Daniel Tryba

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.