【问题标题】:Filter and extract only emails with a certain domainname仅过滤和提取具有特定域名的电子邮件
【发布时间】:2017-08-07 07:22:21
【问题描述】:

我想知道如何匹配某些电子邮件(带有所需的域名)一个例子;

我想提取所有以“.es”或“.pt”、“.com.mx”等结尾的电子邮件...我编写了一个小脚本来过滤一些电子邮件; “hotmail.com”、“aol.com”、“gmail.com”...

  <?php

    $emails = $_POST['emails'];
    $ex     = explode("\n", $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;
    }
}
?>

【问题讨论】:

  • .*@.*?\.(es|pt|pt|com.mx) 类似的东西

标签: php regex email


【解决方案1】:

不要使用strstr(),而是使用带有preg_match_all() 的正则表达式。您的正则表达式应类似于 .+@.+\.((?:es)|(?:pt))(不要忘记完成它)。

【讨论】:

    猜你喜欢
    • 2019-10-12
    • 2018-04-30
    • 2017-09-05
    • 2021-10-16
    • 2012-08-23
    • 1970-01-01
    • 2022-06-26
    • 2022-12-05
    • 1970-01-01
    相关资源
    最近更新 更多