tp.php 文件:
/*
tq 天气
qs 趋势
rq 日期
wd 温度
fx 风向
address 地址
qq 805830
*/
include_once('./include/tq/function.inc.php');
$staid = sta_id();
$ip = getip();
//$address = convertip($ip);
$address = addr();
echo $address. ;
function open($file,$type=''){
if($open=file($file)){
$count=count($open);
for($i=0;$i
$theget.=$open[$i];
}
}else{
die('请求过多,超时,请刷新');
}
return $theget;
}
$_str = open('http://www.weathercn.com/tqyb/detail.jsp?sta_id='.$staid);
//echo $_str;
/**
变量说明:
$str 要进行操作的字符串;
$split 拆分目标字符(串);
$from_no 从第几个开始;
$desc_y_n 顺取(〉0的值)还是倒取(0);
*/
//$_str = aaa .1..aaa.2..aaa .3..aaa.4..aaa.5..bbb..7.bbb.8..bbb.9..bbb.10..bbb;
$split_a = 中国气象局;
$split_b = 时至;
$str_b = strstr($_str,$split_b);//寻找$split_b第一次出现的位置
$str_a = substr($_str,0,strpos($_str, $split_b));//可以取得字符串的指定长度子字符串
function _getstr_from_to($str,$split,$from_no,$desc_y_n)
{
$arr = explode($split,$str);
$size = sizeof($arr);
$from_no = ($from_no
unset($_tmp_out_str);
if($desc_y_n)
{
//正序
for($i=$from_no;$i
{
$_tmp_out_str .= $split.$arr[$i];
}
}
else
{
$_tmp_from = $size - $from_no;
for($i=0;$i
{
$_tmp_out_str .= $arr[$i].$split;
}
}
return $_tmp_out_str;
}
$srting = _getstr_from_to($str_a,中国气象局,1,1);
//echo $srting;
preg_match_all('/alt=([^]*)/',$srting,$tq);
$tq = $tq[1];
if (is_array($tq))
$tq = implode('转',$tq);
//print_r($tq);
echo $tq. ;
preg_match_all('/([0-9-]*℃)~([0-9-]*℃)/',$srting,$wd);
$wd = $wd[0];
$wd = $wd[0];
print_r($wd);
?>
复制代码function.inc.php 文件
=strlen($string)){
return $string;
}
$s=;
for($i=0;$i
if(ord($string{$i})>127){
$s.=$string{$i}.$string{++$i};
continue;
}else{
$s.=$string{$i};
continue;
}
}
return $s....;
}
function getpagebar($count = 0)
{
$bad_link_color = #c0c0c0;
$page[url] = eregi_replace(&page=[^&]+,,basename($_server[script_name]).?.$_server[query_string]);
$page[result_count] = (string) $count;
$page[this_page] = (empty($_get[page]))?1:$_get[page];
$page[this_page] = ($page[result_count] == 0)?0:$page[this_page];
$page[page_size] = $globals[option][page_size];
$page[page_count] = (string) ceil($page[result_count]/$page[page_size]);
$page[first_page] = ($page[this_page] > 1)?«:;
$page[rearward_page] = ($page[this_page] »:;
$page[prev_page] = ($page[this_page] > 1)?‹:;
$page[next_page] = ($page[this_page] ›:;
$page['start_page'] = ((int)$page[this_page]-5
$page['end_page'] = ((int)$page[this_page]+5 > $page['page_count'])?(int)$page[page_count]:(int)$page[this_page]+5;
for ($i = $page['start_page'];$i
{
$selected = ($_get[page] == $i)?selected:;
$page[page_select] .= $i;
$page[page_list] .= ($i == $page[this_page])? $i :[$i];
}
return $page;
}
function getrows($table,$order='')
{
if (!empty($order))
{
$order = explode(',',$order);
$order = 'order by `'.$order[0].'` '.$order[1];
}
$query = dbquery(select * from `.$globals['prefix'].$table.` .$order.;);
while ($row = dbarray($query))
{
$link[$row['id']] = $row;
}
return $link;
}
function autotime($time)
{
preg_match('/([0-9]*)-([0-9]*)-([0-9]*) ([0-9]*):([0-9]*):([0-9]*)/',$time,$date);
return mktime ($date[4],$date[5],$date[6],$date[2],$date[3],$date[1]);
}
function gettime() {
$t = explode(' ', microtime());
return $t[1] + $t[0];
}
function calendar($time)
{
$start = mktime(0, 0, 0, date('m', $time), 1, date('y', $time));
$prev_month['year'] = date('y',$start-86400);
$prev_month['month'] = date('m',$start-86400);
$end = mktime(0, 0, 0, date('m', $time)+1, 1, date('y', $time));
$next_month['year'] = date('y',$end);
$next_month['month'] = date('m',$end);
$sweekday=array('日','一','二','三','四','五','六');
//$sweekday=array('s','m','t','w','t','f','s');
$title=date('m y', $time);
$str = '';
$str .=
«
{$title}
»
{$sweekday[0]}
{$sweekday[1]}
{$sweekday[2]}
{$sweekday[3]}
{$sweekday[4]}
{$sweekday[5]}
{$sweekday[6]}
end;
$year = (empty($_get['year']))?date('y'):$_get['year'];
$month = (empty($_get['month']))?date('m'):$_get['month'];
$query = dbquery(select from_unixtime(date,'%e') as `day`,count(*) as `count` from `.$globals['prefix'].article`,`.$globals['prefix'].article_class` where from_unixtime(date,'%y/%m') = '.$year./.$month.' and `status` = 'published' and .$globals['prefix'].article.class_id = .$globals['prefix'].article_class.id and `in_main_page` = 1 group by `day`;);
for ($i = 0;$i
{
$row = dbarray($query);
$calendar[$row['day']] = $row['count'];
}
for ($i = 0;$i
{
$str.= '
'; }
for($stamp=$start;$stamp
{
$weekday=date('w', $stamp);
$day = date('d', $stamp);
if(date('y-m-d', $stamp)==date('y-m-d')) $style='today';
else if(date('w', $stamp)==0 || date('w', $stamp)==6) $style='weekend';
else $style='weekday';
$str.= .'
'; $str.= ($calendar[date('j', $stamp)] > 0)?''.(int)$day.'':(int)$day;
$str.= '
'. ; if(date('w', $stamp)==6) $str.= .'
'. ; }
$str .= '
'; return $str;
}
//php利用纯真ip数据库查地址的函数
function convertip($ip) {
if(!preg_match(/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/, $ip)) {
return '';
}
if($fd = @fopen( e:hostswkhddbipdatawry.dat, 'rb')) {//fopen()中是纯真ip数据库文件位置,请自行设定!
$ip = explode('.', $ip);
$ipnum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3];
$databegin = fread($fd, 4);
$dataend = fread($fd, 4);
$ipbegin = implode('', unpack('l', $databegin));
if($ipbegin
$ipend = implode('', unpack('l', $dataend));
if($ipend
$ipallnum = ($ipend - $ipbegin) / 7 + 1;
$beginnum = 0;
$endnum = $ipallnum;
while($ip1num > $ipnum || $ip2num
$middle= intval(($endnum + $beginnum) / 2);
fseek($fd, $ipbegin + 7 * $middle);
$ipdata1 = fread($fd, 4);
if(strlen($ipdata1)
fclose($fd);
return '系统错误';
}
$ip1num = implode('', unpack('l', $ipdata1));
if($ip1num
if($ip1num > $ipnum) {
$endnum = $middle;
continue;
}
$dataseek = fread($fd, 3);
if(strlen($dataseek)
fclose($fd);
return '系统错误';
}
$dataseek = implode('', unpack('l', $dataseek.chr(0)));
fseek($fd, $dataseek);
$ipdata2 = fread($fd, 4);
if(strlen($ipdata2)
fclose($fd);
return 'system error';
}
$ip2num = implode('', unpack('l', $ipdata2));
if($ip2num
if($ip2num
if($middle == $beginnum) {
fclose($fd);
return 'unknown';
}
$beginnum = $middle;
}
}
$ipflag = fread($fd, 1);
if($ipflag == chr(1)) {
$ipseek = fread($fd, 3);
if(strlen($ipseek)
fclose($fd);
return '系统错误';
}
$ipseek = implode('', unpack('l', $ipseek.chr(0)));
fseek($fd, $ipseek);
$ipflag = fread($fd, 1);
}
if($ipflag == chr(2)) {
$addrseek = fread($fd, 3);
if(strlen($addrseek)
fclose($fd);
return 'system error';
}
$ipflag = fread($fd, 1);
if($ipflag == chr(2)) {
$addrseek2 = fread($fd, 3);
if(strlen($addrseek2)
fclose($fd);
return 'system error';
}
$addrseek2 = implode('', unpack('l', $addrseek2.chr(0)));
fseek($fd, $addrseek2);
} else {
fseek($fd, -1, seek_cur);
}
while(($char = fread($fd, 1)) != chr(0))
$ipaddr2 .= $char;
$addrseek = implode('', unpack('l', $addrseek.chr(0)));
fseek($fd, $addrseek);
while(($char = fread($fd, 1)) != chr(0))
$ipaddr1 .= $char;
} else {
fseek($fd, -1, seek_cur);
while(($char = fread($fd, 1)) != chr(0))
$ipaddr1 .= $char;
$ipflag = fread($fd, 1);
if($ipflag == chr(2)) {
$addrseek2 = fread($fd, 3);
if(strlen($addrseek2)
fclose($fd);
return 'system error';
}
$addrseek2 = implode('', unpack('l', $addrseek2.chr(0)));
fseek($fd, $addrseek2);
} else {
fseek($fd, -1, seek_cur);
}
while(($char = fread($fd, 1)) != chr(0))
$ipaddr2 .= $char;
}
fclose($fd);
if(preg_match('/http/i', $ipaddr2)) {
$ipaddr2 = '';
}
$ipaddr = $ipaddr1; // 完整地址为 $ipaddr1 $ipaddr2
$ipaddr = preg_replace('/cz88.net/is', '', $ipaddr);
$ipaddr = preg_replace('/^s*/is', '', $ipaddr);
$ipaddr = preg_replace('/s*$/is', '', $ipaddr);
if(preg_match('/http/i', $ipaddr) || $ipaddr == '') {
$ipaddr = 'unknown';
}
return $ipaddr;
} else {
$datadir = phpcms_root.'./ipdata/';
$ip_detail = explode('.', $ip);
if(file_exists($datadir.$ip_detail[0].'.txt')) {
$ip_fdata = @fopen($datadir.$ip_detail[0].'.txt', 'r');
} else {
if(!($ip_fdata = @fopen($datadir.'0.txt', 'r'))) {
return 'invalid ip data file';
}
}
for ($i = 0; $i
$ip_detail[$i] = sprintf('%03d', $ip_detail[$i]);
}
$ip = join('.', $ip_detail);
do {
$ip_data = fgets($ip_fdata, 200);
$ip_data_detail = explode('|', $ip_data);
if($ip >= $ip_data_detail[0] && $ip
fclose($ip_fdata);
return $ip_data_detail[2].$ip_data_detail[3];
}
} while(!feof($ip_fdata));
fclose($ip_fdata);
return '未知地址';
}
}
// station_id 函数
function sta_id(){
include_once('./include/tq/config.inc.php');
include_once('./include/tq/error.inc.php');
include_once('./include/tq/mysql.inc.php');
include_once('./include/tq/template.inc.php');
unset($onlineip);
if($_server['http_client_ip']){
$onlineip=$_server['http_client_ip'];
}elseif($_server['http_x_forwarded_for']){
$onlineip=$_server['http_x_forwarded_for'];
}else{
$onlineip=$_server['remote_addr'];
}
$ips = $onlineip;
$addr = convertip($ips);
$address = $addr;
$address = str_replace(array('省','市','县','工业','北京','区','大学','武汉','西安','安交','海交','新疆','大连','广西'),array(' ',' ',' ',' 工业','北京 ',' ',' ','武汉 ','西安 ','安 交','海 交','新疆 ','大连 ','广西 '),$address);
$addresss = explode( ,$address);
$address1 = $addresss[0];
$address2 = $addresss[1];
$address3 = $addresss[2];
$address4 = $addresss[3];
$query = dbquery(select count(*) as num from .weather_station. where province like '$address1' );//查询 省字段 数目
$row = dbarray($query);
$number = $row[num];
if($number>0 && $address2'' && $address1上海 && $address1重庆){
unset($addresss[0]);
}
if($address4==''){
unset($addresss[3]);
}
if($address3==''){
unset($addresss[2]);
}
$query = dbquery(select count(*) as num from .weather_station. where station like '$address4' );//查询 县 字段
$row = dbarray($query);
$number = $row[num];
if($number==0){
unset($addresss[3]);
}
$query = dbquery(select count(*) as num from .weather_station. where station like '$address3' );//查询 县 字段
$row = dbarray($query);
$number = $row[num];
if($number==0){
unset($addresss[2]);
}
//数组数据2 查询开始
$queryx = dbquery(select count(*) as nums from .weather_station. where station like '$address2' );//查询 县 字段
$row = dbarray($queryx);
$nums = $row[nums];
$queryy = dbquery(select count(*) as numd from .weather_station. where district like '$address2' );//查询 市 字段
$row = dbarray($queryy);
$numd = $row[numy];
if($nums==0 && $numd==0){
unset($addresss[1]); // 如果 数组数据2 不在数据库里则删除数据2
}
//数组数据2 查询结束
$query = dbquery(select count(*) as num from .weather_station. where district like '$address2' );//查询 市 字段
$row = dbarray($query);
$number = $row[num];
if($number>1 && $address3'' && $nums0 && $address2广州 ){
unset($addresss[1]); // 如果数组数据2在数据库里有 多个 则删除数据2
}
@extract(dbquery(select count(*) as num_0 from .weather_station. where district like '$address1' ));//查询 市 字段
@extract(dbquery(select count(*) as num_1 from .weather_station. where station like '$address2' ));//查询 县 字段
$number = $num_0;
$numbery = $num_1;
if($number>1 && $numbery>0 && $address2''){
unset($addresss[0]); //如果数组数据1在数据库里有 多个 则删除数据1
}
$addresss = implode(,$addresss);
//字符串处理完毕 下面开始查询 station_id
$query1 = dbquery(select count(*) as nums_addresss from .weather_station. where station like '$addresss' );
$row1 = dbarray($query1);
$nums_addresss = $row1[nums_addresss];
$query2 = dbquery(select count(*) as numd_addresss from .weather_station. where district like '$addresss' );
$row2 = dbarray($query2);
$numd_addresss = $row2[numd_addresss];
if($nums_addresss>0){
$result = dbquery(select station_id from .weather_station. where station like '$addresss' order by id);
$r = dbarray($result);
$station_id[] = $r[station_id];
$station_id = $station_id[0];
return $station_id; // 查询结果
}
if($nums_addresss==0 && $numd_addresss>0){
$result = dbquery(select station_id from .weather_station. where district like '$addresss' order by id);
$r = dbarray($result);
$station_id[] = $r[station_id];
$station_id = $station_id[0];
return $station_id; // 查询结果
//echo $station_id;
}
}
function get_real_ip()
{
$ip=false;
if(!empty($_server[http_client_ip]))
{
$ip = $_server[http_client_ip];
}
if (!empty($_server['http_x_forwarded_for']))
{
$ips = explode (, , $_server['http_x_forwarded_for']);
if ($ip)
{
array_unshift($ips, $ip); $ip = false;
}
for ($i = 0; $i
{
if (!eregi (^(10|172.16|192.168)., $ips[$i]))
{
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_server['remote_addr']);
}
function addr(){
include_once('./include/tq/config.inc.php');
include_once('./include/tq/error.inc.php');
include_once('./include/tq/mysql.inc.php');
include_once('./include/tq/template.inc.php');
unset($onlineip);
if($_server['http_client_ip']){
$onlineip=$_server['http_client_ip'];
}elseif($_server['http_x_forwarded_for']){
$onlineip=$_server['http_x_forwarded_for'];
}else{
$onlineip=$_server['remote_addr'];
}
$ips = $onlineip;
$addr = convertip($ips);
$address = $addr;
$address = str_replace(array('省','市','县','工业','北京','区','大学','武汉','西安','安交','海交','新疆','大连','广西'),array(' ',' ',' ',' 工业','北京 ',' ',' ','武汉 ','西安 ','安 交','海 交','新疆 ','大连 ','广西 '),$address);
$addresss = explode( ,$address);
$address1 = $addresss[0];
$address2 = $addresss[1];
$address3 = $addresss[2];
$address4 = $addresss[3];
$query = dbquery(select count(*) as num from .weather_station. where province like '$address1' );//查询 省字段 数目
$row = dbarray($query);
$number = $row[num];
if($number>0 && $address2'' && $address1上海 && $address1重庆){
unset($addresss[0]);
}
if($address4==''){
unset($addresss[3]);
}
if($address3==''){
unset($addresss[2]);
}
$query = dbquery(select count(*) as num from .weather_station. where station like '$address4' );//查询 县 字段
$row = dbarray($query);
$number = $row[num];
if($number==0){
unset($addresss[3]);
}
$query = dbquery(select count(*) as num from .weather_station. where station like '$address3' );//查询 县 字段
$row = dbarray($query);
$number = $row[num];
if($number==0){
unset($addresss[2]);
}
//数组数据2 查询开始
$queryx = dbquery(select count(*) as nums from .weather_station. where station like '$address2' );//查询 县 字段
$row = dbarray($queryx);
$nums = $row[nums];
$queryy = dbquery(select count(*) as numd from .weather_station. where district like '$address2' );//查询 市 字段
$row = dbarray($queryy);
$numd = $row[numy];
if($nums==0 && $numd==0){
unset($addresss[1]); // 如果 数组数据2 不在数据库里则删除数据2
}
//数组数据2 查询结束
$query = dbquery(select count(*) as num from .weather_station. where district like '$address2' );//查询 市 字段
$row = dbarray($query);
$number = $row[num];
if($number>1 && $address3'' && $nums0 && $address2广州 ){
unset($addresss[1]); // 如果数组数据2在数据库里有 多个 则删除数据2
}
@extract(dbquery(select count(*) as num_0 from .weather_station. where district like '$address1' ));//查询 市 字段
@extract(dbquery(select count(*) as num_1 from .weather_station. where station like '$address2' ));//查询 县 字段
$number = $num_0;
$numbery = $num_1;
if($number>1 && $numbery>0 && $address2''){
unset($addresss[0]); //如果数组数据1在数据库里有 多个 则删除数据1
}
$addresss = implode(,$addresss);
return $addresss; // 结果
}
?>
复制代码config.inc.php