发布个查询手机归属地的API

 
更多

查询手机归属地的API

<?php

//调用方式域名后加上 ?mobile=13006764649
function Mobile_Ownership($Mobile) {
	if (! empty ( $Mobile )) {
		$Url = 'http://www.ip138.com:8080/search.asp?mobile=' . $Mobile . '&action=mobile';
		$Result = file_get_contents ( $Url );
		$start_str = strpos ( $Result, '<TABLE width=349 border="1"' );
		$end_str = strrpos ( $Result, '<center><iframe' );
		$sublen = $end_str - $start_str;
		$Result = substr ( $Result, $start_str, $sublen );
		$Result = preg_replace ( array ('#<!--.*-->#Uis', '#<a.*</a>#Uis' ), array ('', '' ), $Result );
		$Result = preg_match_all ( '#<td.*>(.*)</td>#Uis', $Result, $arr );
		array_shift ( $arr );
		$Result_arr = $arr [0];
		$Find_arr = array ();
		$Find_arr ['Mobile'] = $Result_arr [2];
		$Find_arr ['guishu'] = Urlencode ( $Result_arr [4] );
		$Find_arr ['kaxing'] = Urlencode ( $Result_arr [6] );
		$Find_arr ['quhao'] = $Result_arr [8];
		$Find_arr ['code'] = $Result_arr [10];
		unset ( $Result, $arr, $end_str, $start_str );
		return json_encode ( $Find_arr );
	}
}

print_r ( json_decode ( Mobile_Ownership ( $_GET ['mobile']), true ) );
?>
打赏

本文固定链接: https://www.cxy163.net/archives/474 | 绝缘体

该日志由 绝缘体.. 于 2012年04月23日 发表在 PHP, 学东西, 首页 分类下,
原创文章转载请注明: 发布个查询手机归属地的API | 绝缘体
关键字: ,

报歉!评论已关闭.