![](/img/trans.png)
[英]PHP Mail() fails with “User <user@example.com>”, fine with “<user@example.com>”
[英]How I separate the host example.com from an e-mail address like user@example.com using PHP?
我需要使用PHP從類似user@example.com的電子郵件地址獲取主機example.com嗎?
有人有主意嗎?
http://php.net/manual/zh/function.explode.php
<?php
$str = 'user@gmail.com';
// positive limit
print_r(explode('@', $str, 2));
?>
//output
Array
(
[0] => user
[1] => gmail.com
)
split()
已棄用; explode()
是解決方法:
$parts = explode("@", $email);
echo "Name: " . $parts[0] . "\n";
echo "Host: " . $parts[1];
碼:
$email = 'user@gmail.com';
$array = explode('@', $email);
var_dump($array);
輸出:
array(
0 => 'user',
1 => 'gmail.com'
)
您可以執行以下操作:
$name = 'someone@gmail.com';
$result = strstr($name, '@');
echo $result;
返回的@ gmail.com
要么
$name = 'someone@gmail.com';
$result = substr(strstr($name, '@'), 1);
echo $result;
返回的gmail.com
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.