Hi! I need to get the host example.com from an e-mail address like [email protected] using PHP?
Anyone have an idea?
Hi! I need to get the host example.com from an e-mail address like [email protected] using PHP?
Anyone have an idea?
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
)
Code:
$email = '[email protected]';
$array = explode('@', $email);
var_dump($array);
Output:
array(
0 => 'user',
1 => 'gmail.com'
)
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
Split() is deprecated. explode() is the way to go.
$parts = explode("@", $email);
echo "Name: " . $parts[0] . "\n";
echo "Host: " . $parts[1];
Cheers,
Fabian