PHP mobile phone number attribution code of API interface and mysql

  • 2020-05-19 04:23:52
  • OfStack

First we introduce the use of their own database query multiple mobile phone Numbers, it is recommended that you have 1 of their own mobile phone number database. Normally, you don't need to buy a professional version of the phone number database to increase the cost if it only satisfies 1 type of query. I will provide you a free ACCESS database containing more than 170,000 pieces of data, including 130-139, 150-159 and 180-189, which you can easily convert into MYSQL or other version of the database with the help of the database tool

Latest mobile number database download address: http: / / xiazai ofstack. com / 201209 / yuanma/phone number - database - jb51. rar

PHP+MYSQL mobile phone number attribution query implementation method

With the introduction above, we have our own MYSQL data table. The structure of this table is simple: ID (serial number), code (area code), num (mobile phone number segment), cardtype (mobile phone card type), city (mobile phone number home). Note that this table stores a large amount of data, and you should create appropriate index fields based on your sql query to improve query efficiency.

1) to get the attribution of mobile phone number, we only need to judge the attribution of mobile phone number segment. It is implemented mainly through the following functions, among which GetAlabNum, cn_substr, str_replace are all string operation functions, and $dsql is the database operation class.
function GetTelphone($tel) 
global $city,$dsql; 
if(isset($tel)) $tel = GetAlabNum(trim($tel));//GetAlabNum Function is used to replace the full Angle number and convert the illegal mobile phone number into a number. trim Remove excess Spaces.  
else return false; 
if(strlen($tel) < 7) return false; 
$tel = cn_substr($tel, 11);// To intercept 11 To prevent multiple phone Numbers  
//if(!is_numeric($tel)) return false; 
if(cn_substr($tel, 1) == "0")// Determine whether the mobile phone number 0 Initially, this might be the case with the landline number 0 At the beginning  
if(cn_substr($tel, 2) == "01" || cn_substr($tel, 2) == "02") $tel = cn_substr($tel, 3);//3 An area code  
else $tel = cn_substr($tel, 4); 
$row = $dsql->GetOne(" Select code,city as dd from `#@__tel` where code='$tel' group by code "); 
$tel = cn_substr($tel, 7); 
$row = $dsql->GetOne(" Select num,city as dd from `#@__tel` where num='$tel' "); 
$city = $row['dd']; 
$city = str_replace(" province ", "-", $city); 
$city = str_replace(" The city ", "", $city); 
$city = "<br /><font color="green">[".$city."]</font>"; 
return $city; 

The api implementation method, where you don't need your own database but you have limitations
Mainly using curl implementation, you need to enable php support for curl.
header( " Content-Type:text/html;charset=utf-8 " ); 
if (isset($_GET['number'])) { 
$url =  ''; 
$number = $_GET['number']; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS,  " mobileCode={$number}&userId= " ); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$data = curl_exec($ch); 
$data = simplexml_load_string($data); 
if (strpos($data,  ' http://')) { 
echo  Wrong phone number format !'; 
} else { 
echo $data; 
<form action= " mobile.php "  method= " get " > 
 Mobile phone number : <input type= " text "  name= " number "  /> <input type= " submit "  value= "Submit"  /> 

This would be much slower to locate with the php mysql mobile phone number, after all, through method 3.

Related articles: