怎么将用户填写的邮箱转换成邮箱地址啊?如下比如:
邮箱: [email protected]                     [email protected]
转换成 :http://mail.163.com           http://mail.qq.com邮箱:[email protected]          [email protected]
转成:http://vip.163.com       http://vip.sina.com
非常感谢

解决方案 »

  1.   

    $mail = '[email protected]';
    echo 'http://' . substr($mail, strpos($mail, '@') + 1);
      

  2.   

    我自己写了个没有vip的。带VIP的要怎么判断啊。
    $_email_url = preg_replace('/^[\w\-\.]+@([\w\-\.]+)([\w\-\.]+)$/','http://mail.$1$2',$_email);
      

  3.   

    $str="[email protected]";$str=preg_replace('/^[a-z]+@[vip]+/i','http://www.',$str);
    echo $str;
      

  4.   

    对,我想两个都判断到。是不是还要做一个preg_match啊。
      

  5.   

    刚才漏掉了MAIL,你用正则没我这个效率高:$mail = '[email protected]';
    echo 'http://mail.'.substr($mail, strpos($mail, '@')+1);
      

  6.   

    vip邮箱不是 http://mail.vip.163.com 是http://vip.163.com
      

  7.   

    非要用正则,在你的基础上:$_email = '[email protected]';
    $_email_url = preg_replace('/^[\w\-\.]+@([\w\-\.]*?)([\w\-\.]+)([\w\-\.]+)$/','http://mail.$1$2$3',$_email);
    echo $_email_url;
      

  8.   

    我用preg_match ,但是感觉没有匹配全,有没有更好的正则啊。谢谢if (preg_match('/^[\w\-\.]+@vip.[\w\-\.]+.[\w\-\.]+$/',$_email)) {
    $_email_url = preg_replace('/^[\w\-\.]+@([\w\-\.]+)([\w\-\.]+)$/','http://$1$2',$_email);
    } else {
    $_email_url = preg_replace('/^[\w\-\.]+@([\w\-\.]+)([\w\-\.]+)$/','http://mail.$1$2',$_email);
    }
      

  9.   

    本帖最后由 PhpNewnew 于 2012-04-11 15:54:11 编辑
      

  10.   

    那如果用户里面出现了vip. 比如 [email protected],那是不是就不行了。。
      

  11.   

    既然是用户填写的邮箱,那查表就是了$dict = array(
      '163.com' => 'http://mail.163.com',
      'qq.com' => 'http://mail.qq.com',
      'vip.163.com' => 'http://vip.163.com',
      'vip.sina.com' => 'http://vip.sina.com',
    );$email = '[email protected]'; //用户填写的邮箱echo $dict[array_pop(explode('@', $email))];
      

  12.   

    PhpNewnew 什么时候变三星啦?
      

  13.   

    要区分VIP,那这样吧:
    $_email = '[email protected]';
    $_email_url = preg_replace('/^[\w\-\.]+@([vip.]?)([\w\-\.]+)([\w\-\.]+)$/e', "('$1')?'http://$1$2$3':'http://mail.$2$3'", $_email);
    echo $_email_url;
      

  14.   


    嘿嘿... ... 你别说,我也是今天才发现,可能是csdn又坏了.
      

  15.   

    $_email = '[email protected]';
    先用@打断,然后检查@后面那个字符串是否有vip,有的话就是http://vip.163.com
    没有的话就是 http://mail.163.com我懒得慌不写代码了。