首先我们介绍使用自己的数据库查询多个手机号码,那还是建议你拥有一个自己的的手机号码数据库。正常情况下,只是满足一般查询的话,你不需要去购买专业版的手机号码数据库,增加无谓成本。我免费为你提供一个ACCESS数据库,包含17万多条数据,常用的130-139、150-159以及180-189开头手机号码段都在其中,你可以借助数据库工具轻松地将它转换成MYSQL或其它版本数据库
最新手机号码数据库下载地址:http://xiazai.jb51.net/201209/yuanma/phone-number-database-jb51.rar
PHP+MYSQL手机号码归属地查询实现方法
通过上面的介绍,我们已经有了自己的MYSQL数据表。这个表结构很简单:ID(序号),code(区号),num(手机号码段),cardtype(手机卡类型),city(手机号码归属地)。注意,这个表存储数据量很大,应当根据你的sql查询语句,建立合适的索引字段,以提高查询效率。
1)获取手机号码归属地,我们只需要通过判断手机号码段归属地即可。主要通过以下函数实现,其中GetAlabNum、cn_substr、str_replace都是字符串操作函数,$dsql是数据库操作类。
复制代码 代码如下:
function GetTelphone($tel)
{
global $city,$dsql;
if(isset($tel)) $tel = GetAlabNum(trim($tel));//GetAlabNum函数用于替换全角数字,将可能存在的非法手机号码转换为数字;trim去除多余空格。
else return false;
if(strlen($tel) $tel = cn_substr($tel, 11);//先截取11个字符,防止是多个手机号码
//if(!is_numeric($tel)) return false;
if(cn_substr($tel, 1) == "0")//判断手机号码是否以0开头,这种情况可能会是座机号以0开头
{
if(cn_substr($tel, 2) == "01" || cn_substr($tel, 2) == "02") $tel = cn_substr($tel, 3);//3位区号
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实现方法,这里不需要自己的数据库但有限制了
主要使用curl实现,需要开启php对curl的支持。
复制代码 代码如下:
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 ‘手机号码格式错误!';
} else {
echo $data;
}
}
?>
与php mysql手机号码归属地查询这个会慢很多,毕竟要通过第三方法数据。

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Herunterladen der Mac-Version des Atom-Editors
Der beliebteste Open-Source-Editor

Dreamweaver Mac
Visuelle Webentwicklungstools

VSCode Windows 64-Bit-Download
Ein kostenloser und leistungsstarker IDE-Editor von Microsoft

SAP NetWeaver Server-Adapter für Eclipse
Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.

EditPlus chinesische Crack-Version
Geringe Größe, Syntaxhervorhebung, unterstützt keine Code-Eingabeaufforderungsfunktion