Page 1 of 1

domain for email

Posted: Mon Aug 01, 2005 11:29 am
by jaymoore_299
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

Posted: Mon Aug 01, 2005 12:00 pm
by hopfateam

Code: Select all

$email_adress="something@something.de";
$explode_email=explode("@",$email_adress);
$domain=$explode_email[1];

Posted: Mon Aug 01, 2005 12:09 pm
by timvw
But user@group@domain is valid too...

Posted: Mon Aug 01, 2005 12:34 pm
by Chris Corbyn
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
    }

}
This 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
    
}

}
?>
EDIT | WTF happened to our tags :(