<?php
//Get regional alarm/warning from http://www.meteoalarm.eu/
// Script by Ken True - saratoga-weather.org
// Version 1.00 - 13-Sep-2008 - Initial Release
// Version 1.01 - 20-Sep-2008 - removed TZ setting (not used), added $EUAtarget option for links
// Version 1.02 - 06-Oct-2008 - some XHTML 1.0-Strict changes for <br />
// Version 2.00 - 22-Apr-2010 - major changes to support major meteoalarm.eu website changes
// Version 2.00 - 22-Apr-2010 - major changes to support major meteoalarm.eu website changes
// Version 2.01 - 02-Oct-2011 - Rivisited alerts icons
//
// Modded by Henkka, nordicweather.net
// error_reporting(E_ALL); // uncomment for error checking
//
// this script is designed to be used by
//   include("get-meteoalarm-warning-inc.php");
//
// Find the warning area for your location by going to www.meteoalarm.eu
// Navigate to the warning area that represents your region and view the detail page for that area.
// For standalone script use,
// Copy the URL in the browser address bar into the $EUA_URL area as shown below.
//
// For Carterlake/WD/PHP template use, add to your Settings.php:
//
// $SITE['EUwarningURL'] = '<URL-to-use-on-meteoalarm.eu>';
//
// where the <URL-to-use-on-meteoalarm.eu> is replaced by the URL in the browser address bar found
// by the method above.  No other customization is needed in the script for use in the Carterlake/WD/PHP template.
// 
// -------------Settings ---------------------------------
  $Lang = 'nl';  // default language to be used (lowercase, must correspond to available 
//               template languages of
//              'en','ct','de','dk','el','es','fi','fr','it','nl','no','pl','pt','se'
//
$isFIN = false; // Does the warning show warnings from Finland? true/false If true, we need to crop
//                the texts as all languages (3) are all in one row...
//
$EUA_URL = 'http://www.meteoalarm.eu/index3.php?area=NL009&day=0&lang=nl_NL';
//$EUA_URL = 'http://www.meteoalarm.eu/index3.php?lang=en_UK&area=DE001&day=0';
//$EUA_URL = 'http://www.meteoalarm.eu/index3.php?area=DE012&day=0&lang=fr_FR';
//
// create a 'meteoalarm-en.txt' file in the same directory as the script.
// you may have to set the permissions on the file to '666' so it is writable
// by the webserver.  Repeat for each language supported by your site.
//
$EUAcacheName = "./meteoalarm.txt";  // prototype for path/filename for cache file
// note: $EUAcacheName will be changed to -$Lang.txt (like -en.txt) to allow languages to have unique cache files.
//
$EUArefetchSeconds = 600;  // refresh every hour
//
$EUAtarget  = 'target="_blank"';  // set to 'target="_blank"' for links.. note: makes output not XHTML 1.0-Strict
//$EUAtarget = 'target="_blank"';  // to launch links in new page .. not XHTML 1.0-Strict though 
// -------------End Settings -----------------------------
//
$EUAversion = 'get-meteoalarm-warning-inc.php V2.07 - 20-Oct-2011';
// the following note is required by agreement with the authors of the website www.meteoalarm.eu
/* -----------------------------------------------------------------------------------------
Date: Thu, 11 Sep 2008 11:39:52 +0200
From: karin buchauer <karin.buchauer@zamg.ac.at>
Organization: zamg

Dear Mr True,

you are quite right:
you can use the material featured on the website, without modifying it, providing the source (link) as well as time and date of issue of the data, as stipulated in the Terms & Conditions.

With best regards,
Karin Buchauer



Ken True schrieb:
> Dear Sirs,
>
> I am an amateur weather enthusiast who also writes scripting for other weather enthusiasts to incorporate weather data into their personal, non-commercial weather websites.  Many of my scripts (which I write as a hobby, and are distributed gratis) are in use on personal weather websites worldwide.
>
> I've had requests to package the excellent data from www.meteoalarm.eu for weather advisories in EU countries, and before I generate a script for that purpose, I'd like to have your permission to proceed.
>
> Your Terms and Conditions page (http://www.meteoalarm.eu/terms.asp?lang=EN ) says:
>
> "The material featured on this site is the common property of the Meteoalarm partners, and is subject to copyright protection.
> The ownership and intellectual rights on all operational and updated awareness and warning information delivered to the Meteoalarm system remain with the Meteoalarm partners who originally delivered this information. The information on this web site may be used freely by the public.
> Before using information obtained from this server special attention should be given to the date & time of the data and products being displayed.
> In case this information is re-used: This information shall not be modified in content and the source of the information has always to be displayed as EUMETNET - MeteoAlarm, or if a single country, the providing national Institute (for internet application in all cases in the form of a link to: www.meteoalarm.eu). The time of issue at www.meteoalarm.eu must be count.
>
> Third parties producing copyrighted works consisting predominantly of the material of this website must provide notice with such work(s) identifying the source of material incorporated and stating that such material is not subject to copyright protection. Further information can be obtained from this following address: meteoalarm@zamg.ac.at"
>
> My reading of this implies that you do permit re-use/publishing of the information with attribution and an active link to the source page for the data on your site, and a note that the data is copyrighted by the data providing organization (and not subject to copyright by the 3rd-party website including/displaying the data).  Is that correct?
>
> Is it ok with you for me to generate a script for displaying national/regional weather alerts using your data from www.meteoalarm.eu with the appropriate attribution.
>
> Please feel free to examine other scripts I've written which use NOAA, Environment Canada, US Geological Services, and temis.nl as data sources (http://saratoga-weather.org/scripts.php ).
>
> Thank you in advance for your response,
>
> Best regards,
> Ken True
> webmaster@saratoga-weather.org
> Saratoga, California, USA

-- 

Karin Buchauer
Assistant to the Project Manager EMMA

Zentralanstalt für Meteorologie und Geodynamik
Regionalstelle für Salzburg und Oberösterreich
Freisaalweg 16
A - 5020 SALZBURG
Fon ++43 (0)662 626301-22
Fax ++43 (0)662 625838
karin.buchauer@zamg.ac.at       www.zamg.ac.at

 ----------------------------------------------------------------------------------------- */
//
// overrides from Settings.php if available
global $SITE;
if (isset($SITE['tz'])) {$ourTZ = $SITE['tz']; }
if (isset($SITE['lang'])) {$Lang = $SITE['lang']; }
if (isset($SITE['EUwarningURL'])) {$EUA_URL = $SITE['EUwarningURL']; }
// end of overrides from Settings.php

if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) {
   //--self downloader --
   $filenameReal = __FILE__;
   $download_size = filesize($filenameReal);
   header('Pragma: public');
   header('Cache-Control: private');
   header('Cache-Control: no-cache, must-revalidate');
   header("Content-type: text/plain");
   header("Accept-Ranges: bytes");
   header("Content-Length: $download_size");
   header('Connection: close');
   
   readfile($filenameReal);
   exit;
}


$EUA_languages = array( // our names for lang= to meteoalarm.eu names for lang=
// the uncommented ones are supported by the WD/AJAX/PHP World-ML template set
  'en' => 'en_UK',  // english
  'ct' => 'ca_ES',  // català
//  'xx' => 'ce_CZ',  // ceština
  'dk' => 'da_DK',  // dansk
  'de' => 'de_GE',  // deutsch
  'es' => 'es_ES',  // español
//  'xx' => 'ee_EE',  // eesti
//  'xx' => 'eu_VA',  // euskera
  'fr' => 'fr_FR',  // français
//  'xx' => 'ga_UK',  // galego
//  'xx' => 'hr_HR',  // hrvatski
//  'xx' => 'is_IS',  // íslenska
  'it' => 'it_IT',  // italiano
//  'xx' => 'li_LT',  // lietuviu
//  'xx' => 'la_LV',  // latviešu
  'hu' => 'ma_HU',  // magyar
//  'xx' => 'ma_MT',  // malti
  'nl' => 'ne_NL',  // nederlands
  'no' => 'no_NO',  // norsk
  'pl' => 'po_PL',  // polski
  'pt' => 'po_PT',  // português
  'ro' => 'ro_RO',  // româna
//  'xx' => 'cp_RS',  // russian
//  'xx' => 'sl_SI',  // slovenšcina
//  'xx' => 'sl_SK',  // slovencina
  'fi' => 'su_FI',  // suomi
  'se' => 'sv_SE',  // svenska
  'el' => 'gr_GR',  // greek
);

$EUA_lang = $EUA_languages[$Lang];

if (isset($_REQUEST['lang'])) {  // 
  $tlang = strtolower($_REQUEST['lang']);
  if (isset($EUA_languages[$tlang])) {
    $EUA_lang = $EUA_languages[$tlang];
	$Lang = $tlang;
	//$Lang = $tlang;
  }
}

print "<!-- lang=$Lang ($EUA_lang) used -->\n";
$EUA_URL = preg_replace('|lang=[^&]+|',"lang=$EUA_lang",$EUA_URL);
$EUAcacheName = preg_replace('|\.txt$|',"-$Lang.txt",$EUAcacheName);

$EUA_URLLink = htmlspecialchars($EUA_URL);

// Translations
if(($Lang == "dk") or ($Lang == '')) {
$intensity = array("Vind", "Sne/Isslag", "Torden", "Skovbrande","Tåge","Ekstremt høje temperaturer","Ekstremt lave temperaturer","Forhøjet vandstand ved kysten","Laviner","Regn");
$levels = array("","Gul","Orange","Rød");
$requiredNoteEUA = '<div class="faqbox rounded" style="text-align:left;margin-top:15px;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>Warning data courtesy of and Copyright &copy; <a href="'.$EUA_URLLink.'"  rel="external">EUMETNET-MeteoAlarm</a>. Time delays between this website and the www.meteoalarm.eu website are possible, for the most up to date information about alert levels as published by the participating National Meteorological Services please use <a href="'.$EUA_URLLink.'" rel="external">www.meteoalarm.eu</a>. Local data provided by <a href="http://www-fmi.fi"  rel="external">Finnish Meteorological Institute</a>. Used with permission.</div>';
} else if($Lang == "se") {
$intensity = array("Vind", "Snö/Is", "Åska", "Skogsbrand","Dimma","Extremt hög temperatur","Extremt låg temperatur","Kusthändelse","Laviner","Regn");
$levels = array("","Gul","Orange","Röd");
$requiredNoteEUA = '<div class="faqbox rounded" style="text-align:left;margin-top:15px;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>Warning data courtesy of and Copyright &copy; <a href="'.$EUA_URLLink.'"  rel="external">EUMETNET-MeteoAlarm</a>. Time delays between this website and the www.meteoalarm.eu website are possible, for the most up to date information about alert levels as published by the participating National Meteorological Services please use <a href="'.$EUA_URLLink.'" rel="external">www.meteoalarm.eu</a>. Local data provided by <a href="http://www.fmi.fi"  rel="external">Finnish Meteorological Institute</a>. Used with permission.</div>';
} else if($Lang == "no") {
$intensity = array("Vind", "Snø/Is", "Torden", "Skogbrann","Tåke","Ekstremt høy temperatur","Ekstremt lav temperatur","Kysthendelse","Snøskred","Regn");
$levels = array("","Gul","Orange","Rød");
$requiredNoteEUA = '<div class="faqbox rounded" style="text-align:left;margin-top:15px;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>Warning data courtesy of and Copyright &copy; <a href="'.$EUA_URLLink.'"  rel="external">EUMETNET-MeteoAlarm</a>. Time delays between this website and the www.meteoalarm.eu website are possible, for the most up to date information about alert levels as published by the participating National Meteorological Services please use <a href="'.$EUA_URLLink.'" rel="external">www.meteoalarm.eu</a>. Local data provided by <a href="http://www.fmi.fi"  rel="external">Finnish Meteorological Institute</a>. Used with permission.</div>';
} else if($Lang == "en") {
$intensity = array("Wind", "Snow/Ice", "Thunderstorms", "Forestfire","Fog","Extreme high temperature","Extreme low temperature","Coastal Event","Avalanches","Rain");
$levels = array("","Yellow","Orange","Red");
$requiredNoteEUA = '<div class="faqbox rounded" style="text-align:left;margin-top:15px;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>Warning data courtesy of and Copyright &copy; <a href="'.$EUA_URLLink.'"  rel="external">EUMETNET-MeteoAlarm</a>. Time delays between this website and the www.meteoalarm.eu website are possible, for the most up to date information about alert levels as published by the participating National Meteorological Services please use <a href="'.$EUA_URLLink.'" rel="external">www.meteoalarm.eu</a>. Local data provided by <a href="http://www.fmi.fi"  rel="external">Finnish Meteorological Institute</a>. Used with permission.</div>';
} else if($Lang == "nl") {
$intensity = array("Wind", "Sneeuw/IJzel", "Onweer", "Bosbranden","Mist","Extreem hoge temperaturen","Extreem lage temperaturen","Wind- en waterhozen","Lawines","Regen");
$levels = array("","Geel","Oranje","Rood");
$requiredNoteEUA = '<div class="faqbox rounded" style="text-align:left;margin-top:15px;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>Warning data courtesy of and Copyright &copy; <a href="'.$EUA_URLLink.'"  rel="external">EUMETNET-MeteoAlarm</a>. Time delays between this website and the www.meteoalarm.eu website are possible, for the most up to date information about alert levels as published by the participating National Meteorological Services please use <a href="'.$EUA_URLLink.'" rel="external">www.meteoalarm.eu</a>. Local data provided by <a href="http://www.knmi.nl"  rel="external">Koninklijk Nederlands Meteorologisch Instituut</a>. Used with permission.</div>';
} else if($Lang == "it") {
$intensity = array("Vento", "Neve/Ghiaccio", "Temporali", "Incendi","Nebbia","Temperature estremamente alte","Temperature estremamente basse","Eventi Costieri","Valanghe","Pioggia");
$levels = array("","Giallo","Arancione","Rosso");
$requiredNoteEUA = '<div class="faqbox rounded" style="text-align:justify;margin-top:15px;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>Si ringrazia <a href="'.$EUA_URLLink.'"  rel="external">EUMETNET-MeteoAlarm&copy;</a> per la pubblicazione degli allarmi meteo. Sono tuttavia possibili ritardi di pubblicazione tra Meteocarmignano.it e www.meteoalarm.eu; Per avere maggiori info sui livelli di allerta pubblicati dal Servizio Meteorologico Nazionale &egrave; consigliabile utilizzare <a href="'.$EUA_URLLink.'" rel="external">www.meteoalarm.eu</a>. I dati e le info locali sono forniti da <a href="http://www.meteoam.it"  rel="external">Servizio Meteorologico dell&acute;Aeronautica</a>. Utilizzo tramite autorizzazione.</div>';
} else if($Lang == "fi") {
$intensity = array("Tuuli", "Lumi/J&auml;&auml;/Keli", "Ukkonen", "Mets&auml;palo","Sumu","Poikkeuksellisen korkea l&auml;mp&ouml;tila","Poikkeuksellisen alhainen l&auml;mp&ouml;tila","Rannikkoalueiden vaarat","Lumivy&ouml;ry","Sade");
$levels = array("","Keltainen","Oranssi","Punainen");
$requiredNoteEUA = '<span class="ui-icon ui-icon-info" style="float: center; margin-right: .3em;"></span>Varoitustiedot tuottaa ja on copyright &copy; <a href="'.$EUA_URLLink.'"  rel="external">EUMETNET-MeteoAlarm</a>. Viivästyksiä tämän websivun ja www.meteoalarm.eu:n välillä saattaa ajoittain esiintyä, tuoreimmat tiedot voimassa olevista varoituksista julkaisee kansalliset ilmatieteen laitkoset sivulla <a href="'.$EUA_URLLink.'" rel="external">www.meteoalarm.eu</a>. Suomen varoitukset tuottaa <a href="http://www.fmi.fi"  rel="external">Ilmatieteen laitos</a>. Käytetty luvalla.</div>';
} else {
$intensity = array("Vind", "Sn&ouml;/Is", "&Aring;ska", "Skogsbrand","Dimma","Extremt h&ouml;g temperatur","Extremt l	&aring;g temperatur","Kusth&auml;ndelse","Laviner","Regn");
$levels = array("","Gul","Orange","R&ouml;d");
$requiredNoteEUA = '<div class="faqbox rounded" style="text-align:left;margin-top:15px;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>Varningarna utfärdas av och är copyright &copy; <a href="'.$EUA_URLLink.'"  rel="external">EUMETNET-MeteoAlarm</a>. Fördröjning mellan denna websida och the www.meteoalarm.eu är möjliga, de nyaste uppgifterna on aktiva varningar från de nationella Meteorologiska instituten går att få på <a href="'.$EUA_URLLink.'" rel="external">www.meteoalarm.eu</a>. Lokal data för Finland produceras av <a href="http://www.fmi.fi"  rel="external">Meteorologiska institutet</a>. Använt med lov.</div>';
}
// Translations end

$wxicon = array("wf_01.jpg","wf_02.jpg","wf_03.jpg","wf_08.jpg","wf_04.jpg","wf_05.jpg","wf_06.jpg","wf_27.jpg","wf_09.jpg","wf_010.jpg");
$levelicon = array("lvlbox1.gif","lvlbox2.gif","lvlbox3.gif","lvlbox4.gif");

if (isset($_REQUEST['debug'])) {$doDebug = false; } else {$doDebug = false; }



print "<!-- $EUAversion -->\n<!-- ".strip_tags($requiredNoteEUA)." -->\n";

// You can now force the cache to update by adding ?force=1 to the end of the URL

if ( empty($_REQUEST['force']) ) 
        $_REQUEST['force']="0";

$Force = $_REQUEST['force'];

if ($Force==1) {
      $html = fetchEUAUrlWithoutHanging($EUA_URL,$EUAcacheName); 
      print "<!-- force reload from URL $EUA_URL -->\n";
      $fp = fopen($EUAcacheName, "w"); 
	  if($fp) {
        $write = fputs($fp, $html); 
        fclose($fp);
	  } else {
	    print "<!--Unable to write cache $EUAcacheName -->\n";
	  }
} 


// refresh cached copy of page if needed
// fetch/cache code by Tom at carterlake.org

if (file_exists($EUAcacheName) and filemtime($EUAcacheName) + $EUArefetchSeconds > time()) {
      $WhereLoaded = "from cache $EUAcacheName";
      $html = implode('', file($EUAcacheName));
    } else {
      $WhereLoaded = "from URL $EUA_URL";
      $html = fetchEUAUrlWithoutHanging($EUA_URL);
      $fp = fopen($EUAcacheName, "w"); 
	  if($fp) {
        $write = fputs($fp, $html); 
        fclose($fp);
	  } else {
	    print "<!--Unable to write cache $EUAcacheName -->\n";
	  }
	}
print "<!-- Meteoalarm data load from $WhereLoaded -->\n";


if(strlen($html) < 50 ) {
  print "<!-- data not available -->\n";
  return;
}

// now slice it up
// Get the table to use:
    preg_match_all('!<td[^>]*(class|width)="([^"]+)"[^>]*>(.*)</td>!Uis',$html,$betweenspan);

  if($doDebug) {
    print "<!-- betweenspan \n" . print_r($betweenspan,true) . " -->\n";
  }
  
  $cTypes = $betweenspan[1];  // contains 'class' or 'width'
  $cNames = $betweenspan[2];  // contains the class="(.*)" or width="(.*)" values
  $cData  = $betweenspan[3];  // contains the <td class="..">(.*)</td> data area
  
  $EUAregionName = '';
  $EUAwarning = '';
  
  $moreInfo = 'More...';

  if($doDebug) {
//    print "<!-- cTypes \n" . print_r($cTypes,true) . " -->\n";
//    print "<!-- cNames \n" . print_r($cNames,true) . " -->\n";
    print "<!-- cData \n" . print_r($cData,true) . " -->\n";
  }

   for ($idx = 0;$idx < count($cData);$idx++) { // loop over the parts to extract the data for use
	if (preg_match_all('|<a href="(.*)".*>\s*<p>(.*)</p>|Uis',$cData[$idx],$matches) ) {
//		print "<!-- moreInfo matches \n".print_r($matches,true)." -->\n";
		if(isset($matches[0]) and count($matches[0]) > 0) {
			// take the last entry
			$i = count($matches[0]) -1;
			$moreInfo = '<a href="' . trim($matches[1][$i]) . '">' . trim($matches[2][$i]).'</a>';
			if ($doDebug) { print "<!-- moreInfo ='$moreInfo' -->\n"; }
		}
 	}
  }
  
  //$EUAregionName = 'MeteoAlarm.eu '. preg_replace('|&nbsp;|',"",strip_tags($cData[0]));
  $EUAwarning = '<table width="100%" style="border: 4px solid #FF7F00; padding: 4px;background-color:  #f2f2f2;">'."\n";
  preg_match_all('|<div class="warnbox wb.">(.*)\t</div>|Uis',$cData[1],$warnboxes);
  if ($doDebug) { print "<!-- warnboxes\n".print_r($warnboxes,true)." -->\n"; }
  for ($idx = 0;$idx < count($warnboxes[1]);$idx++) {  // loop over the warning box notices
  $rawle = '';
  $leic = '';
  $rawic = '';
  $wxic = '';
     $rawWarning = trim($warnboxes[1][$idx]);
	 if ($doDebug) { print "<!-- rawWarning ='$rawWarning' -->\n"; }
	 $EUAwarning .= "<tr>\n";
	 preg_match('|<img src="(.*)"|',$rawWarning,$matches);
	 $warnImg = $matches[1];
	 if ($doDebug) { print "<!-- warnImg ='$warnImg' -->\n"; }
	 preg_match_all('|<div class="([^"]+)".*>(.*)</div>|Uis',$rawWarning,$matches);
   if($doDebug) { print "<!-- detail matches \n".print_r($matches,true)." -->\n"; }
   
   // wxicon
   preg_match_all('|<b>(.*)</b>|Uis',$matches[0][1],$ic);
   $rawic = str_replace("&nbsp;",'',$ic[1][0]);
   $wxic = str_replace($intensity, $wxicon, $rawic);
   if($wxic <> '') {
   $wxic = '<br/><img style="padding:3px" src="http://www.meteoalarm.eu/Bilder/wf/'.$wxic.'" alt=""/>';
   }

   // level
   $rawle = str_replace("&nbsp;",'',$ic[1][1]);
   $leic = str_replace($levels, $levelicon, trim($rawle));
   if($wxic <> '') {
   $acva = true;
   $leic = '<img style="padding:3px" src="http://www.meteoalarm.eu/theme/style1/rssimg/'.$leic.'" alt=""/>';
   } else {
   $leic = '<img style="padding:3px" src="http://www.meteoalarm.eu/theme/style1/rssimg/'.$levelicon[0].'" alt=""/>';
   }
   
	 $warnTxt = '';
	 foreach ($matches[2] as $i => $txt) {
		 $t = strip_tags($txt,'<b>');
		 if (strlen($t)>0) {$warnTxt .= $t . "<br/>\n";}
	 }
	 if ($doDebug) { print "<!-- warnTxt ='$warnTxt' -->\n"; }
	 
	 if($isFIN == true && $acva == true) {
	 $strip = explode(")", $warnTxt);
	 if($Lang == "en") { $warnTxt = $strip[0].')'; }
	 elseif($Lang == "en") { $warnTxt = $strip[1].')'; }
	 else { $warnTxt = $strip[2].')'; }
	 }

	 $EUAwarning .= '<td width="60" style="text-align:center;">
	 '.$leic.'
	 '.$wxic.'
	 </td>'."\n";
	 $EUAwarning .= '<td align="left">'.utf8_decode($warnTxt).'</td>'."\n";
	 $EUAwarning .= "  </tr>\n";
	 
  }
  $EUAwarning .= "</table>\n";

if(($acva == true && $frontpage == true) || $frontpage == false) {
print "<h4>$EUAregionName</h4>\n";
print "$EUAwarning";
} else {
$requiredNoteEUA = false;
}
return; 

// ----------------------------functions ----------------------------------- 


 
 function fetchEUAUrlWithoutHanging($url) // thanks to Tom at Carterlake.org for this script fragment
   {
   // Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
   $numberOfSeconds=4;   

   // Suppress error reporting so Web site visitors are unaware if the feed fails
   error_reporting(0);

   // Extract resource path and domain from URL ready for fsockopen

   $url = str_replace("http://","",$url);
   $urlComponents = explode("/",$url);
   $domain = $urlComponents[0];
   $resourcePath = str_replace($domain,"",$url);

   // Establish a connection
   $socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);

   if (!$socketConnection)
       {
       // You may wish to remove the following debugging line on a live Web site
        print("<!-- Network error: $errstr ($errno) -->\n");
       }    // end if
   else    {
       $xml = '';
       fputs($socketConnection, "GET $resourcePath HTTP/1.1\r\nHost: $domain\r\nConnection: Close\r\n\r\n");
   
       // Loop until end of file
       while (!feof($socketConnection))
           {
           $xml .= fgets($socketConnection, 4096);
           }    // end while

       fclose ($socketConnection);

       }    // end else
	  

   return($xml);

   }    // end function
   
// ----------------------------------------------------------
      
?>