Home  >  Article  >  php教程  >  批量在线查询手机号码归属地信息,淘宝接口,实时更新。外行作品,大牛完善

批量在线查询手机号码归属地信息,淘宝接口,实时更新。外行作品,大牛完善

PHP中文网
PHP中文网Original
2016-05-26 08:21:081524browse

php代码

<?php
$handle = fopen("tel.txt", "r");
if ($handle) {
    //打开要写入的文件对象
   
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
		$content = get_mobile_area(trim($buffer));
		echo "手机号:   ".$buffer."		归属地:   ".$content.&#39;<br/>&#39;;
		if(strpos($content,&#39;北京&#39;) !== false){
			 $file=fopen("北京.txt","a+");
			 fwrite($file,trim($buffer)."	".$content."\n");
			 fclose($file);
			}else if(strpos($content,&#39;上海&#39;) !== false){
				 $file1=fopen("上海.txt","a+");
				 fwrite($file1,trim($buffer)."	".$content."\n");
				 fclose($file1);
				}else{
					 $file2=fopen("外省.txt","a+");
					 fwrite($file2,trim($buffer)."	".$content."\n");
					 fclose($file2);
					}

		
		
		
	    
    }
    
    fclose($handle);
}

function get_mobile_area($mobile){ 
if($mobile!=&#39;&#39;){
    $sms = array(&#39;province&#39;=>&#39;&#39;, &#39;supplier&#39;=>&#39;&#39;);    //初始化变量 
    //根据淘宝的数据库调用返回值 
    $url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobile."&t=".time(); 

    $contents = file_get_contents($url); 

    $sms[&#39;province&#39;] = substr($contents, "56", "4");  //截取字符串 
    $sms[&#39;supplier&#39;] = substr($contents, "81", "4"); 

    return $sms[&#39;province&#39;]."	".$sms[&#39;supplier&#39;];
	
	}
} 
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn