天気情報APIをGETして表示する http://www.duboot.com/lab/weather/Simple_XMLを使って、XMLを解析できるってことです。//地域名称取得 $city_name = $xml->location->attributes(); $place = $city_name["pref"] ." ". $city_name["city"];とかやってハッシュで値をゲットできる、便利だなー。
[sourcecode language="php"]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>天気情報APIサンプル</title>
</head>
<body>
<?php
//Simple_XMLでの実装
$base_url = "http://weather.livedoor.com/forecast/webservice/rest/v1?city=34&day=today";//データ取得
$xml = simplexml_load_file($base_url);//地域名称取得
$city_name = $xml->location->attributes();
$place = $city_name["pref"] ." ". $city_name["city"];//画像情報取得
$img = $xml->image->url;
$img_width = $xml->image->width;
$img_height = $xml->image->height;//リンク先取得
$url = $xml->link;
$description = nl2br($xml->description);//日付取得
$date_rfc822 = $xml->forecastdate;
$date = date("m/j(D)",strtotime($date_rfc822));
$telop = $xml->telop;//出力
print <<< OUT_END
<div>
<div>
{$place} ({$date})
<img src=$img border="0" alt=$place hegiht="$img_height" width="$img_width">
{$telop}</div>
</div>
OUT_END;
?>
</body>
</html>
<pre>[/sourcecode]