这是一个PHP实现的查询手机号码归属地的小程序,限于篇幅原因仅列出少数号码查询。摘录在此仅为了说明如何操作文件。运行mobile_inq.php 查询。
1. mobile_inq.php
<?php
/*
+--------------------------------------------------------------------------
| 手机号码归属地查询
+--------------------------------------------------------------------------
*/
class Debug {
function startTimer() {
global $starttime;
$mtime = microtime ();
$mtime = explode (' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
}
function endTimer() {
global $starttime;
$mtime = microtime ();
$mtime = explode (' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = round (($endtime - $starttime), 5);
return $totaltime;
}
}
function get_data1(){
// hand input
$m = trim($_POST['m']);
if(ereg('[0-9]{7,11}',$m)){
$m = substr($m,'0','7');
if(!$fp = @fopen('./Mobile.php','r')){
echo 'File err!';
exit();
}
flock($fp,LOCK_SH);
$note = fread($fp,filesize('./Mobile.php'));
fclose($fp);
$note = explode("/n",$note);
array_pop($note);
array_pop($note);
array_shift($note);
$num = count($note);
$_data = '';
for($i=0;$i<$num;$i++){
$row = explode(" ",$note[$i]);
if($m >= $row[0] && $m <= $row[1]){
$_data = $row;
break;
}
}
if($_data != ''){
foreach($row as $v){
if($v != ""){
$data1[] = $v;
}
}
return $data1;
}else{
return false;
}
}else{
echo '输入的手机号码错误!';