<?php set_time_limit(0); $handle = fopen("tel.txt", "r"); if ($handle) { //打开要写入的文件对象 $i=0; while (!feof($handle)) { $i++; if( $i%500 == 0 ){ sleep(60); } $buffer = fgets($handle, 4096); $content = get_mobile_area(trim($buffer)); $content.=PHP_EOL; file_put_contents("./data.txt",$content,FILE_APPEND); //写入一个txt 文件中。 } fclose($handle); } function get_mobile_area($mobile){ if($mobile!=''){ $sms = array('province'=>'', 'supplier'=>''); //初始化变量 //根据淘宝的数据库调用返回值 $url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobile."&t=".time(); $contents = file_get_contents($url); $sms['province'] = substr($contents, "56", "4"); //截取字符串 $sms['supplier'] = substr($contents, "81", "4"); return $sms['province']." ".$sms['supplier']; } } ?>