filter email addresses (in PHP)

Discussion in 'Programming/Scripts' started by edge, Jan 31, 2008.

  1. edge

    edge Active Member Moderator

    I have a list here with some email addresses that need to be "cleaned"
    The list is in a text file, and looks like this
    * the list does have more email addresses, and this is only an example.

    Now I need some PHP code to ONLY show all the email addresses from domain1.com (and if needed only from domain2.com or domain3.com ect...)

    Someone here who can show me how this is done? (I guess it needs to make use of a wild card for the pre @ part)

    Thank you
     
  2. topdog

    topdog Active Member

    Code:
    <?php
    # [email protected]
    #
    $file = "path_to_file";
    $domain = "domain1.com";
    
    if(file_exists($file)){
            $x = fopen($file,"r");
            if($x){
                    while(!feof($x)){
                            $b = fgets($x, 4096);
                            if (eregi($domain, $b))
                                    print "$b\n";
    
                    }
                    fclose($x);
            }
    }else{
            print "File $file does not exist";
    }
    ?>
    
     
  3. edge

    edge Active Member Moderator

    Thank you Andrew!

    I'll be testing your code later today.
     

Share This Page