Home  >  Article  >  Backend Development  >  PHP 将邮箱转成邮件地址,该怎么处理

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

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

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);
}

最好多给几个例子,如果就你给的例子就这么写咯。
正则当然是能不用就不用,不过经过长时间观察,在这种小东西上,实在没必要去争取那一点点效率啥的.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn