First we introduce the use of your own database to query multiple mobile phone numbers, it is recommended that you have a mobile phone number database. Under normal circumstances, just to meet the general query, you do not need to buy the professional version of the mobile phone number database, increase the cost of unnecessary. I offer you an Access database for free, with more than 170,000 data, the usual 130-139, 150-159, and 180-189 phone number segments, which you can easily convert to MySQL or other version databases with 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 the implementation method
We already have our own MySQL data sheet through the above introduction. This table structure is simple: ID (serial number), code (area code), NUM (cell phone number segment), Cardtype (mobile card type), City (mobile number attribution). Note that this table stores a large amount of data and should be based on your SQL query statement to establish an appropriate index field to improve query efficiency.
1) to obtain the cell phone number attribution, we only need to determine the cell phone number segment attribution. Mainly through the following functions, where Getalabnum, Cn_substr, str_replace are string manipulation functions, $dsql is the database operation class.
Copy CodeThe code is as follows:
function Gettelphone ($tel)
{
Global $city, $dsql;
if (Isset ($tel)) $tel = Getalabnum (Trim ($tel)), the//getalabnum function is used to replace the full-width number, to convert a possible illegal mobile phone number to a number, and trim to remove extra spaces.
else return false;
if (strlen ($tel) < 7) return false;
$tel = Cn_substr ($tel, 11);//intercept 11 characters to prevent multiple mobile numbers
if (!is_numeric ($tel)) return false;
if (Cn_substr ($tel, 1) = = "0")//Determine whether the mobile phone number starts with 0, this situation may be the landline number starts with 0
{
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 ' Dede_tel ' where code= ' $tel ' Group by Code ');
}
Else
{
$tel = Cn_substr ($tel, 7);
$row = $dsql->getone ("Select Num,city as DD from ' Dede_tel ' where num= ' $tel '");
}
$city = $row [' DD '];
if ($city)
{
$city = Str_replace ("province", "-", $city);
$city = Str_replace ("City", "" ", $city);
$city = "
[". $city."] ";
return $city;
}
}
API implementation method, where you do not need your own database, but there is a limit
The main use of curl implementation, need to open PHP support for curl.
Copy CodeThe code is as follows:
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 is wrong! ';
} else {
Echo $data;
}
}
?>
With the PHP MySQL mobile phone number attribution to query this will be much slower, after all, through the third method data.
http://www.bkjia.com/PHPjc/325877.html www.bkjia.com true http://www.bkjia.com/PHPjc/325877.html techarticle First we introduce the use of your own database to query multiple mobile phone numbers, it is recommended that you have a mobile phone number database. Under normal circumstances, just to meet the general query ...