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

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

以下是filterUserEmail.php文件的源码

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

    if(file_exists($newFile)){
        exit("该文件已存在,请重新命名
");
    }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."
");
        }
        echo "一共".count(file($filePath))."条数据,本次处理".count($emailList[0])."条数据
";
    }
?>
原文地址:https://www.cnblogs.com/wangkongming/p/3326525.html