From c26eeb7fb74886d0d003c63bb97e8f396cf05ccc Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Tue, 20 Jun 2017 21:58:46 +0100 Subject: Initial import --- index.php | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 index.php (limited to 'index.php') diff --git a/index.php b/index.php new file mode 100644 index 0000000..a9f4db2 --- /dev/null +++ b/index.php @@ -0,0 +1,90 @@ + + + + + + + + +loadHTML(file_get_contents("http://www.gov.je/weather/Pages/Jersey-Forecast.aspx")); + +$divs = $dom->getElementsByTagName("div"); + +$day = 0; + +$valid = array(); +$temp = array(); +$misc = array(); + +foreach ($divs as $div) { + if ($day > 2) { + break; + } + + foreach ($div->attributes as $attr) { + if ($attr->nodeValue == "forecastValid") { + array_push($valid, $div->nodeValue); + $day++; + } + + if ($attr->nodeValue == "forecastText" || $attr->nodeValue == "forecastText last") { + array_push($misc, $div->nodeValue); + } + + if ($attr->nodeValue == "main") { + $spans = $div->getElementsByTagName("span"); + foreach ($spans as $span) { + foreach ($span->attributes as $sattr) { + if ($sattr->nodeValue == "temp" || $sattr->nodeValue == "currentc") { + array_push($temp, $span->nodeValue); + } + } + } + } + } + +} + +// Replace newlines with spaces, and strip multiple spaces +for ($i = 0; $i < count($misc); $i++) { + $misc[$i] = preg_replace("/[\r\n]+/", " ", $misc[$i]); + $misc[$i] = preg_replace("/\s+/", " ", $misc[$i]); +} + +for ($i = 0; $i < count($temp); $i++) { +// $temp[$i] = str_replace("°", "°", $temp[$i]); +} + +echo "Max $temp[0], Min $temp[1], Cur $temp[2], $misc[0]\n\n"; +echo "\n\n"; +echo "\n\n"; + +echo "

Forecasts | Graphs

\n\n"; + +echo "

Today

\n\n"; +echo "

$valid[0]

\n"; +echo "Max: $temp[0], Min: $temp[1], Current: $temp[2]

\n"; +echo "Summary: $misc[0]

\n"; +echo "Visibility: $misc[1]

\n"; +echo "Wind: $misc[2]

\n"; +echo "Sea state: $misc[3]

\n\n"; + +echo "

Tomorrow

\n\n"; +echo "

$valid[1]

\n"; +echo "Max: $temp[3], Min: $temp[4]

\n"; +echo "Summary: $misc[4]

\n"; +echo "Wind: $misc[5]

"; + +?> + + + + -- cgit v1.2.3