First we introduce the use of their own database to query multiple mobile phone numbers, it is recommended that you have a database of your own mobile phone number. Under normal circumstances, just to meet the general query, you do not need to buy a professional version of the mobile phone number database, increase the cost of unnecessary. I provide you with an Access database for free, with more than 170,000 data, 130-139, 150-159, and 180-189 initial cell phone numbers, which you can easily convert to MySQL or other versions of your database with the help of database Tools.
Latest Mobile phone number database download address: Http://xiazai.jb51.net/201209/yuanma/phone-number-database-jb51.rar
Php+mysql mobile phone number attribution to query implementation method
Through the above introduction, we already have our own MySQL datasheet. This table structure is very simple: ID (ordinal), Code (area code), NUM (cell phone number), Cardtype (cell phone card type), City (mobile phone number attribution). Note that this table stores a large amount of data, should be based on your SQL query statements, establish the appropriate index fields to improve query efficiency.
1 to obtain the mobile phone number attribution, we only need to judge the number of mobile phone numbers belong to the place. Mainly through the following functions, where Getalabnum, Cn_substr, str_replace are string manipulation functions, $dsql is the database operation class.
Copy Code code as follows:
function Gettelphone ($tel)
{
Global $city, $dsql;
if (Isset ($tel)) $tel = Getalabnum (Trim ($tel)), the//getalabnum function replaces full-width digits, converts possible illegal phone numbers to numbers, and trim removes extra spaces.
else return false;
if (strlen ($tel) < 7) return false;
$tel = Cn_substr ($tel, 11);//First intercept 11 characters to prevent multiple cell phone numbers
if (!is_numeric ($tel)) return false;
if (Cn_substr ($tel, 1) = = "0")//To determine whether the mobile phone number begins with 0, this may be a landline number with 0 start
{
if ($tel, 2) = = "Cn_substr" | | cn_substr ($TEL, 2) = = "$tel = Cn_substr ($tel, 3);//3-bit area code
else $tel = Cn_substr ($tel, 4);
$row = $dsql->getone ("Select Code,city as DD from ' #@__tel ' where code= ' $tel ' GROUP by Code");
}
Else
{
$tel = Cn_substr ($tel, 7);
$row = $dsql->getone ("Select Num,city as DD from ' #@__tel ' where num= ' $tel '");
}
$city = $row [' DD '];
if ($city)
{
$city = Str_replace ("province", "-", $city);
$city = Str_replace ("City", "" ", $city);
$city = "<br/><font color=" green ">[". $city. "] </font> ";
return $city;
}
}
API implementation method, there is no need for its own database, but there are limitations
The main use of curl implementation, need to open PHP to curl support.
Copy Code code as follows:
<?php
Header ("Content-type:text/html;charset=utf-8″");
if (isset ($_get[' number ')) {
$url = ' Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo ';
$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);
Curl_close ($ch);
$data = simplexml_load_string ($data);
if (Strpos ($data, ' http://')) {
Echo ' Phone number format error! '
} else {
Echo $data;
}
}
?>
<form action= "mobile.php" method= "Get" >
Mobile number: <input type= "text" name= "number"/> <input type= "Submit" value= "submitted"/>
</form>
With PHP MySQL phone number attribution to the query this will be much slower, after all, to pass the third method data.