dqssst0144 2017-08-07 07:22
浏览 55
已采纳

仅过滤和提取具有特定域名的电子邮件

I would like to know how to match certain emails (with requiered domainames) an exaple;

I would like to extract all email with the ending ".es" or ".pt", ".com.mx" etc... I've coded a little script to filter some emails; "hotmail.com", "aol.com", "gmail.com"...

  <?php

    $emails = $_POST['emails'];
    $ex     = explode("
", $emails);
    $count  = count($ex);
    if (isset($emails) && $count >= 1) {
        echo "<center><font color = 'red'><b>$count </font>Number of emails  </b></center><br />";
    } else {
        echo "<center>  
    No email </center>";
        exit;
    }

    if (isset($emails)) {


        for ($i = 0; $i <= $count; $i++) {
            $d = strtolower($ex[$i]);

            if (strstr($d, "@hotmail") || strstr($d, "@live") || strstr($d, "@msn") || strstr($d, "@outlook")) {
                $hotmail .= $d;
                $nh = $nh + 1;
            } else {
                if (strstr($d, "@yahoo") || strstr($d, "@ymail")) {
                    $yahoo .= $d;
                    $ny = $ny + 1;
    }
}
?>
  • 写回答

1条回答 默认 最新

  • dpnhp20440 2017-08-07 07:34
    关注

    Instead of strstr(), use regular expressions with preg_match_all(). Your regular expression should look like .+@.+\.((?:es)|(?:pt)) (Do not forget to complete it).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)