tags:

views:

120

answers:

3

Whose argument will contain string data consisting of a valid email address. this function will take the email addres as the argument and return an array with two keys: user to the username part and domain for the domain part of the address

Example:

$arr= SplitEmailAddress('[email protected]')

$arr['user'] should contain the string ----> myusername

$arg['domain'] should contain the string ----> website.example.com

+1  A: 

My take:

function SplitEmailAddress($email){
    return explode("@", $email);
}

But since it's one line, no need for a function just.

$arg = explode('@', '[email protected]');

Will work just fine.

jerebear
A: 

Assuming email is always valid, the easiest would be:

function SplitEmailAddress($email)
{
    list($name, $domain) = explode('@', $email, 2);
    return array(
        'user' => $name,
        'domain' => $domain,
    );
}
Qwerty
+2  A: 

Something like this:

function SplitEmailAddress($email) { // valid email input assumed.
        $temp = explode('@',$email);
        return array("user" => $temp[0], "domain" => $temp[1]);
}
codaddict