用程序过滤大文本数据里面的邮箱

如果一个文本文件里面的数据比较多,有几万条数据,想把不是邮箱的该过滤掉,该怎么处理?

以下是filterUserEmail.php文件的源码

<?php
    /**
     *过滤用户邮箱的脚本
     *argv[1]  获取用户输入文件的路径
     *Author komiles
     *Date   2013-09-17
     */
    $filePath = $argv[1];
    $newFile  = $argv[2];

    if(file_exists($newFile)){
        exit("该文件已存在,请重新命名\n");
    }else{
        $result = file_get_contents($filePath);
        $pattern = '/([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/';
        preg_match_all($pattern, $result, $emailList);
        $handle = fopen($newFile,a);
        foreach($emailList[0] as $value){        
            fwrite($handle , $value."\n");
        }
        echo "一共".count(file($filePath))."条数据,本次处理".count($emailList[0])."条数据\n";
    }
?>

 

posted @ 2013-09-17 16:23  KoMiles  阅读(359)  评论(0编辑  收藏  举报