最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php获取google当前天气实现程序
时间:2013-01-06 编辑:简简单单 来源:一聚教程网
se.php
$city = $_GET['city'];
代码如下
复制代码
$data = createXml($city);
$xml = simplexml_load_string($data);
header("Content-type: text/xml");
echo $xml->asXML();
// 生成XML数据
function createXml($city)
{
// Google 天气API
$weather = simplexml_load_file("http://www.google.com/ig/api?weather={$city}");
if(isset($weather->weather->forecast_conditions))
{
$low = f2c($weather->weather->forecast_conditions->low['data']);
$high = f2c($weather->weather->forecast_conditions->high['data']);
return "
}
else
{
return "
}
}
// 华氏度转摄氏度
function f2c($fahrenhite)
{
return floor(($fahrenhite - 32) / 1.8);
}
客户端 c.php
代码如下 | 复制代码 |
if(!empty($_POST['city'])) { $city = $_POST['city']; $xml = simplexml_load_file("http://127.0.0.1/rest/se.php?city={$city}"); $html = " City:{$xml->city} n";$html .= " Low:{$xml->low} n";$html .= " High:{$xml->high} n";echo $html; } ?> |
-
上一个: PHP缓冲ob_start和页面文件缓存
-
下一个: 一个简单php 抽奖小程序
相关文章
- php获取http状态码程序代码 07-27
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24