PDA

View Full Version : Weather data and PHP 5 . . .


Intrigued
10-09-2004, 12:26 PM
Here is an example I read about in the PHP 5 book I am reading. I modified it slightly. Remember, this uses a absolute URL path... and may become unreliable at some point. So, make sure if you use it to check that web page often, or code it differently.

<?php

print "<H1>NAME OF CITY GOES HERE!</H1>"; // example: print "<H1>Redmond</H1>";

?>

<br/> <!-- break out of PHP to add this break -->

<?php

$zip = CHOOSE A ZIP CODE; // example: $zip = 98052;

$weather_page = file_get_contents('http://www.srh.noaa.gov/zipcity.php?inputstring=' . $zip);

$page = strstr($weather_page, 'Detailed Forecast');

$table_start = strpos($page, '<table');

$table_end = strpos($page, '</table>') + 8;

print substr($page, $table_start, $table_end - $table_start);

?>

If someone has a different way of doing such in PHP 5 (or that works in PHP 5) then by all means please share! This is starting to get fun! :p

Note: I am very new to PHP in general, so don't pistol whip me to bad... ;)