Displaying the weather
This example will display the weather depending on either what US zip code or city is entered . An improved example would allow the users to enter this information via a form . All of this is freely available at http://www.weather.com .
Code :
<?
//insert a valid US zipcode in here e.g 22222 or you can enter a city
$zipcode = 55555;
//make our url
$url = "http://www.weather.com/weather/local/".$zipcode."?y=16&x=11";
//open the $url for reading
$fp = fopen($url, "r");
$search = fread($fp, 64000);
//close the file handle
fclose($fp);
//our start point and end points , store the rest in $content
$search = ereg("<!-- end svr wx alert -->(.*)<!-- 10 day forecast -->", $search, $content);
//display content
echo "$content[1]";
?> |