开发者

How I separate the host example.com from an e-mail address like user@example.com using PHP?

I need to get the host example.com from an e-mail address like user@example开发者_开发知识库.com using PHP?

Anyone have an idea?


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
)


split() is deprecated; explode() is the way to go:

$parts = explode("@", $email);
echo "Name: " . $parts[0] . "\n";
echo "Host: " . $parts[1];


Code:

$email = 'user@gmail.com';
$array = explode('@', $email);
var_dump($array);

Output:

array(
  0 => 'user',
  1 => 'gmail.com'

)


You can do the following:

$name = 'someone@gmail.com';
$result = strstr($name, '@');
echo $result;

return's @gmail.com

or

$name = 'someone@gmail.com';
$result = substr(strstr($name, '@'), 1);
echo $result;

return's gmail.com

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜