<?php

// scraps the rain meassurement from DublinAirport
// http://www.dublinairportweather.com/index.htm

// $url= "http://exampledomain.com"
 $url= "http://www.dublinairportweather.com/index.htm";
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
 $result = curl_exec($ch);  //you need to figure out what is the format of the output, sometimes you need to work on this variable in order to print it
 curl_close($ch);

// echo $result; //if a simple string
// print_r($result); //if an array
// echo print_r(json_decode($result)); //if a json object and want to print it as a php array
// echo htmlentities($result); //if a html or xml object <-- this is tricky, html format can change often on a web interface so it needs a lot of maintenance

$rain1 = '';
$wind2 = '';
$temp1 = '';
$kts = '';
$dewpt1  = '';
$pressure1  = '';
$humidity1 = '';
$cloudbase = '';

// Rainfall Last Hour:</strong> 0.5 mm<br>


$lines_array = explode("\n", $result);
foreach ($lines_array  as $key => $val) {

# Get wind speed and direction
 if (strpos($val,'Rainfall Last Hour:') == true) {
   echo "LINE Num:".$key." : LINE :".  $val ."\r\n"; 
   preg_match('/>(.*?)</', $val, $rain_arr);
   print_r($rain_arr);
   // echo "WIND1:".$wind1."\r\n";
   // print_r($wind1);

   // $wind_array = explode("/", $wind1[1]);
   // print_r($wind_array[1]);
   $rain1 = str_replace( 'mm','', $rain_arr[1]);
   // $wdgs = str_replace( '&deg;','', $wind_array[0]);
   // echo "BOB \r\n";
   // echo "KTS :". $kts. "\r\n";
 }

}

// exit;

?>

<html>
<head>
<meta http-equiv="refresh" content="65">
</head>

[<?php echo $rain1; ?>]

</body>
</html>

