PHP mobile phone number retrieval code (API/mysql) _ PHP Tutorial

Source: Internet
Author: User
PHP mobile phone number retrieval code (API mysql ). This article introduces the implementation of mobile phone number attribution. we can use the api interface and mysql + php to check if you need it. First, we will introduce how to use our database to check the article to introduce the implementation of mobile phone number attribution. we can use the api interface and mysql + php to check if the instance is needed.

First, we will introduce how to use your own database to query multiple mobile phone numbers. we recommend that you have your own mobile phone number database. Under normal circumstances, you do not need to purchase the mobile phone number database of the Professional edition to increase unnecessary costs. I will provide you with an ACCESS database for free, containing more than 0.17 million pieces of data. the commonly used 130-139, 150-159, and mobile phone number segments starting with 180-189 are all in it, you can use the database tool to easily convert it to MYSQL or another version of the database.

Latest mobile phone number database: http://www.bKjia. c0m/down/phone-number-database.rar

PHP + MYSQL mobile phone number attribution query implementation method
Through the above introduction, we already have our own MYSQL data table. This table has a simple structure: ID (serial number), code (area code), num (mobile phone number segment), cardtype (mobile phone card type), and city (mobile phone number attribution ). Note: This table stores a large amount of data. you should create appropriate index fields based on your SQL query statements to improve query efficiency.
1) to obtain the location of the phone number, we only need to determine the location of the phone number segment. The following functions are mainly implemented: GetAlabNum, cn_substr, and str_replace are all string operation functions, and $ dsql is a database operation class.

The code is as follows:
Function GetTelphone ($ tel)
{
Global $ city, $ dsql;
If (isset ($ tel) $ tel = GetAlabNum (trim ($ tel); // The GetAlabNum function is used to replace a full-width number and convert an invalid mobile phone number to a number; trim unnecessary spaces.
Else return false;
If (strlen ($ tel) <7) return false;
$ Tel = cn_substr ($ tel, 11); // truncates 11 characters to prevent multiple phone numbers.
// If (! Is_numeric ($ tel) return false;
If (cn_substr ($ tel, 1) = "0") // determines whether the phone number starts with 0. in this case, the landline number may start with 0.
{
If (cn_substr ($ tel, 2) = "01" | cn_substr ($ tel, 2) = "02") $ tel = cn_substr ($ tel, 3 ); // Three-digit 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. you do not need to use your own database, but there are restrictions.
This is mainly implemented using curl. you need to enable php's support for curl.

The 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 'mobile phone number format error! ';
} Else {
Echo $ data;
}
}
?>

It is much slower to query php mysql mobile phone numbers. after all, you need to use the third method of data.

Bytes. First, we will introduce how to use our own database to query...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.