All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQLSERVER2005的混和身份验证模式的设置以及SA登陆问题_[SQL Server教程]
.NET2.0在Repeater中实现删除_[Asp.Net教程]
推荐:让你的MySQL数据库彻底与中文联姻_php资料_编程技术
注意那些容易被忽略的SQL注入技巧_[SQL Server教程]_0
用动态网页制作技术PHP制作大型网站问题集_php资料_编程技术
复杂ASP.NET服务器控件调整小技巧_.net资料_编程技术
Spring集成XFire开发WebService_.net资料_编程技术
ASP.NET底层架构探索之处理请求_.net资料_编程技术
程序开发者使用最多的五个PHP工具_php资料_编程技术
如何用.NET,Array类的Sort方法分类数值_.net资料_编程技术
Reading number is top 10 pictures
Average female college students3
Sora aoi after swimming
赵惟依写真1
So beauty, will let you spray blood5
Players in the eyes of a perfect love1
网上疯传的一篇小学作文《爸爸也治不了妈妈》
美洲杯宝贝的雨中风情2
So beauty, will let you spray blood3
Absolutely shocked. National geographic 50 animal photographys9
Chinese paper-cut grilles art appreciation8
Download software ranking
Proficient in JavaScript
Boxer vs Yellow5
徐若瑄成名作“魔鬼天使”
株洲本地在线棋牌游戏
Boxer's Top ten classic battle2
The cock of the Grosvenor LTD handsome
Unix video tutorial11
matrix1
Boxer's Top ten classic battle4
Love the forty days
归海一刀 published in(发表于) 2014/2/17 7:31:15 Edit(编辑)
PHP实例:PHP天气查询_[PHP教程]

PHP实例:PHP天气查询_[PHP教程]

PHP实例:PHP天气查询_[PHP教程]


city_name=_GET['city'];


//用正则在city.txt中查找相应城市的天气城市代码
city_name=trim(ereg_replace("[ ]{1,}","",city_name));
time_file="city.txt";


city_all=file_get_contents(time_file);
preg="|city_name,(.*)\s|i";
preg_match_all(preg,city_all,cn, PREG_SET_ORDER);
city_n=trim(cn[0][1]);



if(city_n)
{
nowtime=date("Y-m-d");


file = "cache/city_name.txt";


//获取文件的最后修改日期
if(file_exists(file))
{
last_time=date("Y-m-d",filemtime(file));
}
else{
last_time=date("Y-m-d");
}
//新建保存匹配数组
records=null;



//如果文件存在,或还没过期,则直接读取缓存数据
if (file_exists(file) && last_time==nowtime)
{

records = unserialize(file_get_contents(file));


}
else
{


//以下就是如何在网站上 获取天气资料,,小偷部分!感觉其中的preg_match_all功能很强大


data=file_get_contents("http://weather.msn.com/local.aspx?wealocations=wc:city_n");
preg="|

Hi:<\/th>
(.*)&#176;<\/td><\/tr>
L<\/th>
(.*)&#176;<\/td><\/tr><\/table>.*class=\"skytext\" colspan=\"3\">(.*)<\/td>|U";


preg_match_all(preg,data,records);
unset (records[0][0]);


//序列化组
OUTPUT = serialize(records);
//打开文件,
fp = fopen(file,"w");
//把数组写进文件
fputs(fp, OUTPUT);
//关闭
fclose(fp);

}

image=records[1][0];
resulta=records[2][0];
resultb=records[3][0];
resultc=records[4][0];
reString="




city_name


nowtime










".resulta."-".resultb."(F)






".resultc."




";
}
else
{
reString="




The city: city_name hasn`t been found!




";
}
echo iconv("gb2312","utf-8",reString);


?>


主要是把当天的做个缓存,这样第2次访问同一城市的时候的话就比较快了。虽然不是什么好代码,但是对与刚刚学习PHP的人还是一个蛮好的例子,特别是里面的正则表达式的应用。


前编主要是处理 部分,也就是天气查询的核心部分,现在是AJAX中的部分 代码如下:


var xmlHttp;
function createXMLHttpRequest()
{
var xmlHttpRequest;
if(window.ActiveXObject)
{
xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttpRequest;


}
else if(window.XMLHttpRequest)
{
xmlHttpRequest=new XMLHttpRequest();
return xmlHttpRequest;
}
}



function startXmlHttpRequest()
{
var form=document.getElementById("city");
var city=form.value;
var cityName=form.Text;

xmlHttp=createXMLHttpRequest();
xmlHttp.open("GET","weather/getHtml.php?city="+city+"&cityname="+cityName+"&time="+new Date(),true);
xmlHttp.onreadystatechange=returnText;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(null);



}
function startTextXmlHttpRequest()
{
var form=document.getElementById("textcity");
var city=form.value;
xmlHttp=createXMLHttpRequest();
xmlHttp.open("GET","weather/textGetHtml.php?city="+city,true);
xmlHttp.onreadystatechange=returnText;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(null);



}


function validataIpAdd()
{

}
function returnText()
{
var div=document.getElementById("result_box");
var loading=document.getElementById("loading");
div.innerHTML="";
loading.style.display="block";
if(xmlHttp.readyState==1)
{

}
else if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{

div.innerHTML=xmlHttp.responseText;
loading.style.display="none";
}
}
}


主要比较简单! 由4个函数组成 1个是创建 1个是提交 一个是返回 顶部的是是判断浏览器然后创建XMLHTMLREQUES


来源:CSDN







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.