国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊 PHP手機(jī)號碼歸屬地查詢代碼(API接口/mysql)

PHP手機(jī)號碼歸屬地查詢代碼(API接口/mysql)

Jun 13, 2016 am 11:58 AM
api mysql php introduce code use Multiple us hand phone number interface database Inquire my own first

首先我們介紹使用自己的數(shù)據(jù)庫查詢多個手機(jī)號碼,那還是建議你擁有一個自己的的手機(jī)號碼數(shù)據(jù)庫。正常情況下,只是滿足一般查詢的話,你不需要去購買專業(yè)版的手機(jī)號碼數(shù)據(jù)庫,增加無謂成本。我免費(fèi)為你提供一個ACCESS數(shù)據(jù)庫,包含17萬多條數(shù)據(jù),常用的130-139、150-159以及180-189開頭手機(jī)號碼段都在其中,你可以借助數(shù)據(jù)庫工具輕松地將它轉(zhuǎn)換成MYSQL或其它版本數(shù)據(jù)庫

最新手機(jī)號碼數(shù)據(jù)庫下載地址:http://xiazai.jb51.net/201209/yuanma/phone-number-database-jb51.rar

PHP+MYSQL手機(jī)號碼歸屬地查詢實(shí)現(xiàn)方法

通過上面的介紹,我們已經(jīng)有了自己的MYSQL數(shù)據(jù)表。這個表結(jié)構(gòu)很簡單:ID(序號),code(區(qū)號),num(手機(jī)號碼段),cardtype(手機(jī)卡類型),city(手機(jī)號碼歸屬地)。注意,這個表存儲數(shù)據(jù)量很大,應(yīng)當(dāng)根據(jù)你的sql查詢語句,建立合適的索引字段,以提高查詢效率。

1)獲取手機(jī)號碼歸屬地,我們只需要通過判斷手機(jī)號碼段歸屬地即可。主要通過以下函數(shù)實(shí)現(xiàn),其中GetAlabNum、cn_substr、str_replace都是字符串操作函數(shù),$dsql是數(shù)據(jù)庫操作類。

復(fù)制代碼 代碼如下:


function GetTelphone($tel)
{
global $city,$dsql;
if(isset($tel)) $tel = GetAlabNum(trim($tel));//GetAlabNum函數(shù)用于替換全角數(shù)字,將可能存在的非法手機(jī)號碼轉(zhuǎn)換為數(shù)字;trim去除多余空格。
else return false;
if(strlen($tel) $tel = cn_substr($tel, 11);//先截取11個字符,防止是多個手機(jī)號碼
//if(!is_numeric($tel)) return false;
if(cn_substr($tel, 1) == "0")//判斷手機(jī)號碼是否以0開頭,這種情況可能會是座機(jī)號以0開頭
{
if(cn_substr($tel, 2) == "01" || cn_substr($tel, 2) == "02") $tel = cn_substr($tel, 3);//3位區(qū)號
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("省", "-", $city);
$city = str_replace("市", "", $city);
$city = "
[".$city."]";
return $city;
}
}


api實(shí)現(xiàn)方法,這里不需要自己的數(shù)據(jù)庫但有限制了
主要使用curl實(shí)現(xiàn),需要開啟php對curl的支持。

復(fù)制代碼 代碼如下:


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 ‘手機(jī)號碼格式錯誤!';
} else {
echo $data;
}
}
?>


手機(jī)號碼:


與php mysql手機(jī)號碼歸屬地查詢這個會慢很多,畢竟要通過第三方法數(shù)據(jù)。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is PHP and What is it Used For? What is PHP and What is it Used For? Jul 16, 2025 am 03:45 AM

PHPisaserver-sidescriptinglanguageusedforwebdevelopment,especiallyfordynamicwebsitesandCMSplatformslikeWordPress.Itrunsontheserver,processesdata,interactswithdatabases,andsendsHTMLtobrowsers.Commonusesincludeuserauthentication,e-commerceplatforms,for

Your First PHP Script: A Practical Introduction Your First PHP Script: A Practical Introduction Jul 16, 2025 am 03:42 AM

How to start writing your first PHP script? First, set up the local development environment, install XAMPP/MAMP/LAMP, and use a text editor to understand the server's running principle. Secondly, create a file called hello.php, enter the basic code and run the test. Third, learn to use PHP and HTML to achieve dynamic content output. Finally, pay attention to common errors such as missing semicolons, citation issues, and file extension errors, and enable error reports for debugging.

How Do You Handle File Operations (Reading/Writing) in PHP? How Do You Handle File Operations (Reading/Writing) in PHP? Jul 16, 2025 am 03:48 AM

TohandlefileoperationsinPHP,useappropriatefunctionsandmodes.1.Toreadafile,usefile_get_contents()forsmallfilesorfgets()inaloopforline-by-lineprocessing.2.Towritetoafile,usefile_put_contents()forsimplewritesorappendingwiththeFILE_APPENDflag,orfwrite()w

PHP 8 Installation Guide PHP 8 Installation Guide Jul 16, 2025 am 03:41 AM

The steps to install PHP8 on Ubuntu are: 1. Update the software package list; 2. Install PHP8 and basic components; 3. Check the version to confirm that the installation is successful; 4. Install additional modules as needed. Windows users can download and decompress the ZIP package, then modify the configuration file, enable extensions, and add the path to environment variables. macOS users recommend using Homebrew to install, and perform steps such as adding tap, installing PHP8, setting the default version and verifying the version. Although the installation methods are different under different systems, the process is clear, so you can choose the right method according to the purpose.

PHP Variable Scope Explained PHP Variable Scope Explained Jul 17, 2025 am 04:16 AM

Common problems and solutions for PHP variable scope include: 1. The global variable cannot be accessed within the function, and it needs to be passed in using the global keyword or parameter; 2. The static variable is declared with static, and it is only initialized once and the value is maintained between multiple calls; 3. Hyperglobal variables such as $_GET and $_POST can be used directly in any scope, but you need to pay attention to safe filtering; 4. Anonymous functions need to introduce parent scope variables through the use keyword, and when modifying external variables, you need to pass a reference. Mastering these rules can help avoid errors and improve code stability.

Advanced PHP Multiline Comment Techniques Advanced PHP Multiline Comment Techniques Jul 17, 2025 am 04:14 AM

UsemultilinecommentsinPHPforfunction/classdocumentation,codedebugging,andfileheaderswhileavoidingcommonpitfalls.First,documentfunctionsandclasseswith/*...*/toexplainpurpose,parameters,andreturnvalues,aidingreadabilityandenablingIDEintegration.Second,

PHP Installation for Beginners PHP Installation for Beginners Jul 17, 2025 am 04:15 AM

Installing PHP is not complicated for novices. The key is to clarify the system environment and version requirements and follow the steps. First, you need to confirm the operating system (Windows, macOS or Linux) and choose a stable version such as PHP8.1 or 8.2; secondly, you can install it through manual installation, using integrated environments (such as XAMPP, WAMP) or package management tools (such as apt-get and brew). Then configure environment variables to ensure that the command line can recognize PHP instructions and run through the phpinfo() page test; finally pay attention to common problems, such as Apache port occupation, php.ini file path errors and extensions not enabled, etc., and check them one by one to complete the installation smoothly.

PHP Operators for Beginners PHP Operators for Beginners Jul 17, 2025 am 04:17 AM

Mastering the commonly used operators of PHP can deal with most development scenarios, mainly including: 1. Arithmetic operators ( , -, , /, %) are used for mathematical calculations and support dynamic variable operations, but pay attention to the problems that may be caused by automatic type conversion; 2. Comparison operators (==, ===, !=, >

See all articles