a

//PEAR::XML_Serializerでの実装方法
require_once("XML/Unserializer.php");
$base_url =
"http://weather.livedoor.com/forecast/webservice/rest/v1?city=63&day=today";
$xmldoc = join("",file($base_url));
$opt = array (
'complexType' => ‘object’,
‘parseAttributes’ => ‘true’,
‘attribuesArray’ => ‘_attributes’,
);
$xml = new XML_Unserializer($opt);
$xml -> unserialize($xmldoc, false);
$xml = $xml->getUnserializedData();
$place = $xml->location->pref . $xml->location->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 <<< DOC_END

{$place}({$date})

$place
{$telop}

{$description}

DOC_END;
?>


//Simple_XMLでの実装方法
$base_url =
"http://weather.livedoor.com/forecast/webservice/rest/v1?city=63&day=tomorrow";
$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 <<< DOC_END

{$place}({$date})

$place
{$telop}

{$description}

DOC_END;
?>

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>