Reputation: 3128
I need to get the host example.com from an e-mail address like [email protected] using PHP?
Anyone have an idea?
Upvotes: 0
Views: 131
Reputation: 34244
split()
is deprecated; explode()
is the way to go:
$parts = explode("@", $email);
echo "Name: " . $parts[0] . "\n";
echo "Host: " . $parts[1];
Upvotes: 2
Reputation: 7283
You can do the following:
$name = '[email protected]';
$result = strstr($name, '@');
echo $result;
return's @gmail.com
or
$name = '[email protected]';
$result = substr(strstr($name, '@'), 1);
echo $result;
return's gmail.com
Upvotes: 1
Reputation: 29917
Code:
$email = '[email protected]';
$array = explode('@', $email);
var_dump($array);
Output:
array(
0 => 'user',
1 => 'gmail.com'
)
Upvotes: 1
Reputation: 43217
http://php.net/manual/en/function.explode.php
<?php
$str = '[email protected]';
// positive limit
print_r(explode('@', $str, 2));
?>
//output
Array
(
[0] => user
[1] => gmail.com
)
Upvotes: 2