<item>
<title>Arêches - Beaufort</title>
<description>Closed / Past 48 Hours: 0 cm / Primary: Hard Packed / Base Depth: 170 cm</description>
<guid isPermaLink="true">http://www.onthesnow.co.uk/france/areches-beaufort/skireport.html?XE_AFF=rss</guid>
<pubDate>Fri, 4 Jun 2010 04:47:05 -0400</pubDate>
<ots:open_staus>Closed</ots:open_staus>
<ots:resort_id>2658</ots:resort_id>
<ots:base_depth>170</ots:base_depth>
<ots:snowfall_48hr>0</ots:snowfall_48hr>
<ots:region_name>France</ots:region_name>
<ots:surface_condition>Hard Packed</ots:surface_condition>
<ots:base_depth_metric>cm</ots:base_depth_metric>
<ots:snowfall_48hr_metric>cm</ots:snowfall_48hr_metric>
<ots:resort_rss_link>http://www.onthesnow.co.uk/france/areches-beaufort/snow.rss</ots:resort_rss_link>
</item>
class SnowData {
public $title;
public $description;
public $pubDate;
// Constructor
//
function __construct( $t, $d, $p ) {
$this->title = $t;
$this->description = $d;
$this->pubDate = $p;
}
}
class SnowData {
public $title;
public $description;
public $pubDate;
// Constructor
//
function __construct( $t, $d, $p ) {
$this->title = $t;
$this->description = $d;
$this->pubDate = strtotime($p);
}
}
class SnowData {
public $title;
public $description;
public $pubDate;
// Constructor
//
function __construct( $t, $d, $p ) {
$this->title = $t;
$this->description = $d;
$this->pubDate = strtotime($p);
}
// Pull the base depth using a regex
//
function getDepth() {
preg_match('~^.*Base Depth:\s+([0-9]+)\s+cm\s*$~', $this->description, $matches );
return $matches[1];
}
}
// Load the XML
//
$xml = simplexml_load_file("http://......rss");
// Array to collect the data
//
$arr = array();
// Process the XML
//
foreach( $xml->channel->item as $anEntry ) {
$arr [] = new SnowData(
(string) $anEntry->title,
(string) $anEntry->description,
(string) $anEntry->pubDate
);
}
// A custom sort based on snow depth
//
function snowDepthSort( $a, $b ) {
$aDepth = $a->getDepth();
$bDepth = $b->getDepth();
if ( $aDepth < $bDepth )
return 1;
else
if ( $aDepth > $bDepth )
return -1;
return 0;
}
// Produce a table
//
$tab = "<table>\n";
foreach( $arr as $aSnowObj ) {
$tab .= "<tr>\n";
$tab .= "<td>\n";
$tab .= $aSnowObj->title . "(" . date("d/m/Y H:i", $aSnowObj->pubDate) . ")";
$tab .= "</td>\n";
$tab .= "<td>\n";
$tab .= $aSnowObj->getDepth();
$tab .= "</td>\n";
$tab .= "</tr>\n";
}
$tab .= "</table>\n";
echo $tab;
class SnowData {
public $location;
public $title;
public $description;
public $pubDate;
// Constructor
//
function __construct( $l, $t, $d, $p ) {
$this->location = $l;
$this->title = $t;
$this->description = $d;
$this->pubDate = strtotime($p);
}
// Pull the base depth using a regex
//
function getDepth() {
preg_match('~^.*Base Depth:\s+([0-9]+)\s+cm\s*$~', $this->description, $matches );
return $matches[1];
}
}
// Process the XML
//
foreach( $xml->channel->item as $anEntry ) {
$arr [] = new SnowData(
"France",
(string) $anEntry->title,
(string) $anEntry->description,
(string) $anEntry->pubDate
);
}
// Produce a table
//
$tab = "<table border='1'>\n";
foreach( $arr as $aSnowObj ) {
$tab .= "<tr>\n";
$tab .= "<td>\n";
$tab .= $aSnowObj->location;
$tab .= "</td>\n";
$tab .= "<td>\n";
$tab .= $aSnowObj->title . "(" . date("d/m/Y H:i", $aSnowObj->pubDate) . ")";
$tab .= "</td>\n";
$tab .= "<td>\n";
$tab .= $aSnowObj->getDepth();
$tab .= "</td>\n";
$tab .= "</tr>\n";
}
$tab .= "</table>\n";
echo $tab;
function collectRSS( $location, $feedUrl, & $arr ) {
// Load the XML
//
$xml = simplexml_load_file( $feedUrl );
// Process the XML
//
foreach( $xml->channel->item as $anEntry ) {
$arr [] = new SnowData(
$location,
(string) $anEntry->title,
(string) $anEntry->description,
(string) $anEntry->pubDate
);
}
}
$arr = array();
collectRSS( "Austria", "http://www.....rss", $arr );
collectRSS( "Austria", "http://www........rss", $arr );
collectRSS( "France", "http://www....rss", $arr );
class SnowData {
public $location;
public $title;
public $description;
public $pubDate;
// Constructor
//
function __construct( $l, $t, $d, $p ) {
$this->location = $l;
$this->title = $t;
$this->description = $d;
$this->pubDate = strtotime($p);
}
// Pull the base depth using a regex
//
function getDepth() {
preg_match('~^.*Base Depth:\s+([0-9]+)\s+cm\s*$~', $this->description, $matches );
return $matches[1];
}
}
// A custom sort based on snow depth
//
function snowDepthSort( $a, $b ) {
$aDepth = $a->getDepth();
$bDepth = $b->getDepth();
if ( $aDepth < $bDepth )
return 1;
else
if ( $aDepth > $bDepth )
return -1;
return 0;
}
function collectRSS( $location, $feedUrl, & $arr ) {
// Load the XML
//
$xml = simplexml_load_file( $feedUrl );
// Process the XML
//
foreach( $xml->channel->item as $anEntry ) {
$arr [] = new SnowData(
$location,
(string) $anEntry->title,
(string) $anEntry->description,
(string) $anEntry->pubDate
);
}
}
// Array to collect the data
//
$arr = array();
// Collect all the data
//
collectRSS( "Austria", "http://www......rss", $arr );
collectRSS( "Italy", "http://www.....snow.rss", $arr );
collectRSS( "France", "http://www....snow.rss", $arr );
// Sort the array into descending snowdepth
//
uasort( $arr, 'snowDepthSort' );
$arr = array_slice( $arr, 0, 10);
// Produce a table
//
$tab = "<table border='1'>\n";
foreach( $arr as $index => $aSnowObj ) {
$tab .= "<tr>\n";
$tab .= "<td>\n";
$tab .= $aSnowObj->location;
$tab .= "</td>\n";
$tab .= "<td>\n";
$tab .= $aSnowObj->title . "(" . date("d/m/Y H:i", $aSnowObj->pubDate) . ")";
$tab .= "</td>\n";
$tab .= "<td>\n";
$tab .= $aSnowObj->getDepth();
$tab .= "</td>\n";
$tab .= "</tr>\n";
}
$tab .= "</table>\n";
echo $tab;
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)