PHP手機(jī)號(hào)碼歸屬地查詢代碼(API接口/mysql)
Jun 13, 2016 am 11:58 AM
首先我們介紹使用自己的數(shù)據(jù)庫(kù)查詢多個(gè)手機(jī)號(hào)碼,那還是建議你擁有一個(gè)自己的的手機(jī)號(hào)碼數(shù)據(jù)庫(kù)。正常情況下,只是滿足一般查詢的話,你不需要去購(gòu)買專業(yè)版的手機(jī)號(hào)碼數(shù)據(jù)庫(kù),增加無(wú)謂成本。我免費(fèi)為你提供一個(gè)ACCESS數(shù)據(jù)庫(kù),包含17萬(wàn)多條數(shù)據(jù),常用的130-139、150-159以及180-189開頭手機(jī)號(hào)碼段都在其中,你可以借助數(shù)據(jù)庫(kù)工具輕松地將它轉(zhuǎn)換成MYSQL或其它版本數(shù)據(jù)庫(kù)
最新手機(jī)號(hào)碼數(shù)據(jù)庫(kù)下載地址:http://xiazai.jb51.net/201209/yuanma/phone-number-database-jb51.rar
PHP+MYSQL手機(jī)號(hào)碼歸屬地查詢實(shí)現(xiàn)方法
通過上面的介紹,我們已經(jīng)有了自己的MYSQL數(shù)據(jù)表。這個(gè)表結(jié)構(gòu)很簡(jiǎn)單:ID(序號(hào)),code(區(qū)號(hào)),num(手機(jī)號(hào)碼段),cardtype(手機(jī)卡類型),city(手機(jī)號(hào)碼歸屬地)。注意,這個(gè)表存儲(chǔ)數(shù)據(jù)量很大,應(yīng)當(dāng)根據(jù)你的sql查詢語(yǔ)句,建立合適的索引字段,以提高查詢效率。
1)獲取手機(jī)號(hào)碼歸屬地,我們只需要通過判斷手機(jī)號(hào)碼段歸屬地即可。主要通過以下函數(shù)實(shí)現(xiàn),其中GetAlabNum、cn_substr、str_replace都是字符串操作函數(shù),$dsql是數(shù)據(jù)庫(kù)操作類。
復(fù)制代碼 代碼如下:
function GetTelphone($tel)
{
global $city,$dsql;
if(isset($tel)) $tel = GetAlabNum(trim($tel));//GetAlabNum函數(shù)用于替換全角數(shù)字,將可能存在的非法手機(jī)號(hào)碼轉(zhuǎn)換為數(shù)字;trim去除多余空格。
else return false;
if(strlen($tel) $tel = cn_substr($tel, 11);//先截取11個(gè)字符,防止是多個(gè)手機(jī)號(hào)碼
//if(!is_numeric($tel)) return false;
if(cn_substr($tel, 1) == "0")//判斷手機(jī)號(hào)碼是否以0開頭,這種情況可能會(huì)是座機(jī)號(hào)以0開頭
{
if(cn_substr($tel, 2) == "01" || cn_substr($tel, 2) == "02") $tel = cn_substr($tel, 3);//3位區(qū)號(hào)
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ù)庫(kù)但有限制了
主要使用curl實(shí)現(xiàn),需要開啟php對(duì)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ī)號(hào)碼格式錯(cuò)誤!';
} else {
echo $data;
}
}
?>
與php mysql手機(jī)號(hào)碼歸屬地查詢這個(gè)會(huì)慢很多,畢竟要通過第三方法數(shù)據(jù)。

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











phphasthreecommentstyles : //, #forsingle-lineand/.../formulti-lline.usecommentstoexplainwhycodeexists, notwhatitdoes.marktodo/fixMeitemsandDisableCodeTemporlinlyDuingDeBugging.aVoidOver-commentingsimplOgic.writeCoCoCoCoCoConcomeCOCOCOCONCOCOCOCOCOCOCOCOCISE

Windows? PHP? ???? ?? ???? ??? ?????. 1. ??? PHP ??? ?????? ?? ??????. Apache? ?? ThreadSafe ??? ????? Nginx??? ThreadSafe ??? ???? ?? ????. 2. php.ini ??? ???? php.ini-development ?? php.ini-production? php.ini? ?????. 3. ?? ? ??? ?? ??? ?? ?? ??? PHP ??? ??????. 4. PHP? ????? ?????? ??? ????? ?? ?? ?? PHP-V? ???? ?? ??? ???? ?? ?? ??? ??????. 5. Apache? ???? ?? httpd.conf?? p? ???????.

phpisaserver-sideScriptingLanguageUsedForWebDevelopment, ?? ProcessesData, InteractSwithDatabases ? SendShtmlTobrowsers.commonusesincludeusera-sectentication, e-commerceplatforms

ToHandleFileOperationsInphp, useAppreptFunctionsandModes.1.TOREADAFILE, USEFILE_GET_CONTENTS () FORSMALLFILESORFGETS () inALOOPFORLE-by-lineProcessing.2.TOWRITETOAFILE, USEFILE_PUTE_CONTENTS () USEFILE_PUTE_CONTENTS () FORSIMPLEWRITE () FORSIMPLAGFILE (ORFENDFLAG)

PHP? ?? ???? 4 ?? ?? ??? ?????. 1. PHP ??? ?????? ??? ??? ???? ?? ?????. 2. Echo ? Print? ????? ?? ???? ????, ??? Echo? ?? ?? ??? ?????? ??????. 3. ?? ???? ?? ???? ??????? //, # ? //; 4. ? ??? ?????? ????? ??? ?? ????? ??? ??? ??? ?? ???? ??? ????. ??? ?? ??? ????? ???? ???? PHP ??? ???? ? ??? ? ? ????.

? ?? PHP ???? ??? ???? ??? ?????? ?? ?? ?? ??? ???? XAMPP/MAMP/LAMP? ?? ? ?? ??? ???? ???? ??? ???? ??? ?????. ??, hello.php?? ??? ??? ?? ??? ???? ???? ??????. ??, PHP ? HTML? ???? ?? ??? ??? ???? ?? ????. ?????, ???? ??, ?? ?? ? ?? ?? ??? ?? ???? ?????? ???? ???? ?? ????? ???????.

???? PHP8? ???? ??? ??? ????. 1. ????? ??? ?? ????; 2. PHP8 ? ?? ?? ??? ??????. 3. ??? ????? ????? ??? ??????. 4. ??? ?? ?? ??? ??????. Windows ???? Zip ???? ?????? ?? ?? ? ?? ?? ??? ???? ???? ????? ?? ??? ??? ?? ? ? ????. MACOS ???? Homebrew? ???? ? ??, PHP8 ??, ?? ?? ?? ? ?? ??? ?? ??? ???? ?? ????. ?? ??? ?? ????? ???? ????? ????? ??? ?? ??? ??? ??? ? ????.

Python? Ifelse ??? ???? ??? ??? ??? ?? ??? ???? ????. 1. ???? ??? ???? ??? ???? ????. ??? ??? ?? ??? ???? ?? ?????. 2. ?? ?? ??? ELIF? ?? ????, ????? ???? ?? ???? ?????. 3. ?? ?? ??? ???? ?? ?? ? ?? ? ?? ???? ?? ?? ????. 4. 3 ?? ??? ??? ?????? ??? ifelse? ???? ? ??? ? ????. ?? ??, ??? ?? ? ??? ??????? ?????? ??? ???? ???? ?? ??? ??? ? ????.
