Apr
23
2012
发布个查询手机归属地的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 ) ); ?>
最活跃的读者