Maison  >  Article  >  développement back-end  >  PHP 将邮箱转成邮件地址,该怎么处理

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

WBOY
WBOYoriginal
2016-06-13 13:37:16955parcourir

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


HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
比如:
邮箱: php@163.com                     php@qq.com
转换成 :http://mail.163.com           http://mail.qq.com

邮箱:php@vip.163.com          php@vip.sina.com
转成:http://vip.163.com       http://vip.sina.com



非常感谢

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

最好多给几个例子,如果就你给的例子就这么写咯。
正则当然是能不用就不用,不过经过长时间观察,在这种小东西上,实在没必要去争取那一点点效率啥的.
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn