Using PHP simple script that parses XML to HTML code for anyone who needs to put weather forecast on their websites
<?php
$xml = simplexml_load_file("http://www.google.com/ig/api?weather=milan");
$day=array();
$low=array();
$high=array();
$icon=array();
$condition =array();
$humidity=array();
$wind_condition=array();
$googlePath="http://www.google.com";
foreach($xml->children() as $child)
{
foreach($child->children() as $schild)
{
if($schild->getName()!=" ")
{
if( $schild->getName()=="forecast_conditions")
{
foreach($schild->children() as $sschild)
{
if( $sschild->getName()=="day_of_week")
{
$day[]= $sschild['data'];
}
if( $sschild->getName()=="low")
{
$low[]= $sschild['data'];
}
if( $sschild->getName()=="high")
{
$high[]= $sschild['data'];
}
if( $sschild->getName()=="icon")
{
$icon[]= $sschild['data'];
}
if( $sschild->getName()=="condition")
{
$condition[]= $sschild['data'];
}
}
}
if( $schild->getName()=="current_conditions")
{
foreach($schild->children() as $sschild)
{
if( $sschild->getName()=="humidity")
{
$humidity= $sschild['data'];
}
if( $sschild->getName()=="wind_condition")
{
$wind_condition = $sschild['data'];
}
}
}
}
}
}
?>
Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!
ReplyDeleteYii Framework Development Company in India