domain for email
Moderator: General Moderators
-
jaymoore_299
- Forum Contributor
- Posts: 128
- Joined: Wed May 11, 2005 6:40 pm
- Contact:
domain for email
if I an email, something@aaa-bbb_ccc.com , how do I get only the domain part and excluding the first part up to the @ ?
Re: domain for email
Code: Select all
$email_adress="something@something.de";
$explode_email=explode("@",$email_adress);
$domain=$explode_email[1];- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I think google would bring up a nice array of regex for you here but here's a partially decent one...

Code: Select all
function get_email_parts($address)
{
if (preg_match('/^([a-z0-9][\w\-\.]*[a-z0-9])@([a-z0-9][\w\-\.]*[a-z0-9])$/i', $address, $matches))
{
return array('local_part' => $matches[1], 'domain_part' => $matches[2]); //Return array
}
else
{
return false; //Doesn't fit the pattern
}
}EDIT | WTF happened to our tagsThis will do for now wrote: <?php
function get_email_parts($address)
{
if (preg_match('/^([a-z0-9][\w\-\.]*[a-z0-9])@([a-z0-9][\w\-\.]*[a-z0-9])$/i', $address, $matches))
{
return array('local_part' => $matches[1], 'domain_part' => $matches[2]); //Return array
}
else
{
return false; //Doesn't fit the pattern
}
}
?>