Re: get domain component from email

From: Date: Tue, 07 Aug 2007 18:56:31 +0000
Subject: Re: get domain component from email
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-260302@lists.php.net to get a copy of this message
What are you trying to do exactly, maybe there's a better way. If you're trying to determine if an email address is valid there's a pretty cool way to do so by using dns records. It's like 5 lines, here's the site http://www.sitepoint.com/article/users-email-address-php As far as actually just getting the domain, w/o subdomains from a string you could try this. I'm not sure if the code runs because I haven't tested it, and I have been working exclusively with Delphi for a month so something might be off. function getDomain($email) { list($userName, $mailDomain) = split("@", $email); $anarray = split(".", $mailDomain); for ($i = 0; $i < count($anarray); $i++) { if (in_array($anarray[$i], $TLDArray)) // if $anarray[$i] is a TDL then we move back 1 to get it's domain
       return $anarray[$i-1] . '.' . $anarray[$i];
} } - Dan "Kevin Waterson" <kevin@oceania.net> wrote in message news:20070808042505.18ac7b4b.kevin@oceania.net...
Hi all. Im looking for a way to get the domain from an email address. Not sub domains, just the domain, so luser@foo.bar.example.com.mn would return example.com.mn similarly, the address luser@example.com would return example.com perhaps an array of tld's, then strip the tld off the end and anything before that and the next "." is the domain? also, somebody told me .co.uk was a tld, but I cannot see it listed http://www.iana.org/root-whois/index.html Kind regards Kevin -- "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote."


« previous php.general (#260302) next »