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

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

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