2-25 2,110 views
txt文件格式如下
13000000000,13000000005,13000000403,13001010129,13001010688,13001010838,13001016389,13001019538,13001030005,13001042700,13001047495,13001049871,13001072727,13001086166,13001103598,13001108955,13001119191,13001119326,13001119381,13001122997,13001125733,13001128598,13001133352,13001159788,13001163638,13001194012,13001200791,13001206309,13001220631,13001222221,13001225210,13001236066,13001242996,13001267978,13001272366,13001279525,13001286377,13001286907,13001303126,13001304654,13001306970,13001313257,13001315988,13001328069,13001339578,13001359703,13001367655,13001397796,13001419112,13001423823,13001433363,13001452385,13001499722,13001505123,13001522177,13001544895,13001551007,13001556934,13001579390,13001590367,13001598184,13001600804,13001608962,13001609052,13001627116,13001631483,13001656358,13001672087,13001681870,13001683508,13001698397,13001707688,13001710692,13001712288,13001719420,13001727188,13001741837,13001742180,13001751202,13001751737,13001751792,13001771448,13001778810,13001785513,13001789795,13001793614,13001793714,13001794854,13001795467,13001796034,13001796475,13001796554,
<?php
$handle = fopen("mobile.txt", "r") or die("Couldn't get handle");
$mobiles = [];
$stime = microtime(true);
$param = '';
$next = false;
$page = 1;
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 500);
// Process buffer here..
preg_match_all('/\d+/', $buffer, $match);
if (empty($match['0'])) {
break;
}
//如果最后一个不是逗号
if (substr($buffer, -1, 1) != ',') {
$next = true;
//判断是不是到最后的一行
$param = array_pop($match['0']);
}
if ($next && $page > 1) {
//如果第一个不是逗号
if (substr($buffer, 0, 1) != ',') {
$param = $param . array_shift($match['0']);
}
$mobiles[] = $param;
$next = false;
$param = '';
}
foreach ($match['0'] as $v) {
$mobiles[] = $v;
}
unset($buffer);
$page++;
}
fclose($handle);
}
if ($next && !empty($param)) {
$mobiles[] = $param;
}
p($arr[0]);
echo count($arr) . "个手机号 \n";