Heim  >  Artikel  >  Backend-Entwicklung  >  PHP 将邮箱转成邮件地址,该怎么处理

PHP 将邮箱转成邮件地址,该怎么处理

WBOY
WBOYOriginal
2016-06-13 10:16:28951Durchsuche

PHP 将邮箱转成邮件地址
怎么将用户填写的邮箱转换成邮箱地址啊?如下


HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->比如:邮箱: [email protected]                     [email protected]转换成 :http://mail.163.com           http://mail.qq.com邮箱:[email protected]          [email protected]转成:http://vip.163.com       http://vip.sina.com


非常感谢

------解决方案--------------------
$str = "[email protected]";
echo getMailServer($str);
function getMailServer($mail) {
if (stripos($mail, 'vip') !== false) {
$pre = '/^[a-z][email protected]/i';
$rep = 'http://vip';
} else {
$pre = '/^[a-z]+@/i';
$rep = 'http://mail.';
}
return preg_replace($pre, $rep, $mail);
}

最好多给几个例子,如果就你给的例子就这么写咯。
正则当然是能不用就不用,不过经过长时间观察,在这种小东西上,实在没必要去争取那一点点效率啥的.
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn