I’m fighting with some php coding to collect weather icon and temperature from one page with "file_get_contents".
I have after couple of days manages to get the script working very well!
But now I’m moved to thin ice again!
This is the working code to collect weather information from Norwegian Metrology institution (NMI).
<?php
$newstring1 = file_get_contents("http://www.yr.no/sted/Norge/Sogn_og_Fjordane/Eid/Nordfjordeid/ekstern_boks_liten.html"); // Recover the target webpage
$pos1 = strpos($newstring1, '<td class="'); // Find the beginning tag of a specific element
$posout1 = strpos($newstring1, '<td class="wind"'); // Find the end tag of the specific element
$pos1 = $pos1+126; // Start position
$result1 = substr($newstring1, $pos1, $posout1-$pos1); // Webpage + Start position + Endposition
echo "$result1; // Print the result
?>
Generate Source Code like this
<img src="http://symbol.yr.no/grafikk/sym/b38/09.png" alt="Regn" width="38" height="38" />
</td>
<td class="plus">10°</td>
On td class, you can find “plus”. This show when the temperature is from 1 degree Celsius and up. When the temperature is from 0 or below, this td class, get “minus”
From this html tags, I want to make rules whit if.
Plus – Show the temperature in read.
Minus – Show the temperature in blue.
This is the code that’s ****ed up the script and my head...
<?php
$newstring1 = file_get_contents("http://www.yr.no/sted/Norge/Sogn_og_Fjordane/Eid/Nordfjordeid/ekstern_boks_liten.html"); // Recover the target webpage
$pos1 = strpos($newstring1, '<td class="'); // Find the beginning tag of a specific element
$posout1 = strpos($newstring1, '<td class="wind"'); // Find the end tag of the specific element
$pos1 = $pos1+126; // Start position
$result1 = substr($newstring1, $pos1, $posout1-$pos1); // Webpage + Start position + Endposition
if ($result1, '== "plus"') echo "<front color=\"#FF0000\>"$result1;
elseif ($result1, '== "minus"') echo "<front color=\"#0000FF\>"$result1;
?>
I reactive error line
Parse error: syntax error, unexpected ',
But, to be honest, am not sure the if code is actual working on my purpose.
Can someone please take over from here and guide me to the end ?? 🙂
Break copyright ??
Negative! It’s allow to collect weather information from NMI and publish to own web page.
My website is still under construction, but when the site is completed, all necessary information will be displayed.
-JayC-