我需要使用PHP从user@example.com这样的电子邮件地址获取主机example.com吗?
有人有想法吗?
答案 0 :(得分:2)
http://php.net/manual/en/function.explode.php
<?php
$str = 'user@gmail.com';
// positive limit
print_r(explode('@', $str, 2));
?>
//output
Array
(
[0] => user
[1] => gmail.com
)
答案 1 :(得分:2)
split()
已被弃用; explode()
是要走的路:
$parts = explode("@", $email);
echo "Name: " . $parts[0] . "\n";
echo "Host: " . $parts[1];
答案 2 :(得分:1)
代码:
$email = 'user@gmail.com';
$array = explode('@', $email);
var_dump($array);
输出:
array(
0 => 'user',
1 => 'gmail.com'
)
答案 3 :(得分:1)
您可以执行以下操作:
$name = 'someone@gmail.com';
$result = strstr($name, '@');
echo $result;
return's @ gmail.com
或
$name = 'someone@gmail.com';
$result = substr(strstr($name, '@'), 1);
echo $result;
return's gmail.com