just thought i should add the source MILDURA (working) <?php //weather("Mildura","http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV17001.txt" ,"bomonster.htm");
weather("Mildura","http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV17001.txt"," bomonster.htm"); function weather($placename, $inputfilename, $templatefilename){ // ############################################################################ # // # BOMonster 0.1 // # Author: Matthew Cook ([EMAIL PROTECTED]) // # // # How to use: // # <$placename> is the place you want to find the forecasts for // # <$inputfilename> is the file you want to grab the data from // # <$templatefilename> is the file you want to put the forecasts into // # Details are in readme.txt // # // # Released under the GNU GPL (http://www.gnu.org/copyleft/gpl.html) // ############################################################################ # //try to connect to target - IDV60035 if(!$fp=fopen($inputfilename ,"r")) { echo "Can't Open Weather File" ; } else { //initalise $content variable $content = ""; // read content while(!feof($fp)){ $content.=fgets($fp,1024); } //close connection fclose($fp); //create new string containing data for selected place preg_match("|$placename.*?\\n\\n.*?\\n\\n|s", $content, $temp); //turn the first element of the temp array into a variable $temp_content = $temp[0]; //split place_content into an array by multiple spaces and single [NL]s $temp_array = preg_split ("/[\s]{2,}|[\n]/", $temp_content); //clean out all the "Min" and "Max" $temp_array = str_replace("Min", "", $temp_array); $temp_array = str_replace("Max", "", $temp_array); //trim entries for ($counter = 0; $counter <= count($temp_array)-1; $counter++){ trim($temp_array[$counter]); } //check for today's description > 80 char if (is_numeric($temp_array[3]) == FALSE){ $temp_array[2] = $temp_array[2]." ".$temp_array[3]; for ($counter = 3; $counter <= count($temp_array)-2; $counter++) { $temp_array[$counter] = $temp_array[$counter+1]; } } //print_r($temp_array); //determine if it's the afternoon/evening variant or not if (preg_match("/Tonight/", $temp_array[1])){ $arvomod = 1; $temp_array = str_replace("Tonight and ", "", $temp_array); } else { $arvomod = 0; } //convert $temp_array into $place_array $place_array["name"][0] = $temp_array[0]; $place_array["name"][1] = $temp_array[1]; $place_array["name"][2] = $temp_array[6+$arvomod]; $place_array["name"][3] = $temp_array[10+$arvomod]; $place_array["name"][4] = $temp_array[14+$arvomod]; $place_array["description"][1] = $temp_array[2]; $place_array["description"][2] = $temp_array[7+$arvomod]; $place_array["description"][3] = $temp_array[11+$arvomod]; $place_array["description"][4] = $temp_array[15+$arvomod]; if ($arvomod = 1){ $place_array["min_temp"][1] = $temp_array[3]; } $place_array["min_temp"][2] = $temp_array[8+$arvomod]; $place_array["min_temp"][3] = $temp_array[12+$arvomod]; $place_array["min_temp"][4] = $temp_array[16+$arvomod]; $place_array["max_temp"][1] = $temp_array[3+$arvomod]; $place_array["max_temp"][2] = $temp_array[9+$arvomod]; $place_array["max_temp"][3] = $temp_array[13+$arvomod]; $place_array["max_temp"][4] = $temp_array[17+$arvomod]; $place_array["precip"][1] = $temp_array[5+$arvomod]; //determine the appropriate images and alt tags for ($counter = 1; $counter <= 4; $counter++){ if (stristr($place_array["description"][$counter], "thunderstorm")){ $place_array["image"][$counter] = "thunder"; $place_array["alt_tag"][$counter] = "Thunderstorms"; } elseif (stristr($place_array["description"][$counter], "shower")){ $place_array["image"][$counter] = "shower"; $place_array["alt_tag"][$counter] = "Showers"; } elseif (stristr($place_array["description"][$counter], "fine")){ $place_array["image"][$counter] = "fine"; $place_array["alt_tag"][$counter] = "Fine"; } else { $place_array["image"][$counter] = "unknown"; $place_array["alt_tag"][$counter] = "Unknown"; } } //create short names for ($counter = 0; $counter <= 4; $counter++){ $place_array["short_name"][$counter] = substr($place_array["name"][$counter], 0, 3); } } //declare template $template = ""; //open template if(!$fp=fopen($templatefilename ,"r")) { echo "Can't Open Template File" ; } else { // read template while(!feof($fp)){ $template.=fgets($fp,1024); } //close connection fclose($fp); //replace some strings $patterns = array( "/(\%Name\[)(.*?)(\]\%)/se", "/(\%Description\[)(.*?)(\]\%)/se", "/(\%Min_Temp\[)(.*?)(\]\%)/se", "/(\%Max_Temp\[)(.*?)(\]\%)/se", "/(\%Precip\[)(.*?)(\]\%)/se", "/(\%Image\[)(.*?)(\]\%)/se", "/(\%Alt_Tag\[)(.*?)(\]\%)/se", "/(\%Short_Name\[)(.*?)(\]\%)/se" ); $replace = array( '$place_array["name"]["\\2"]', '$place_array["description"]["\\2"]', '$place_array["min_temp"]["\\2"]', '$place_array["max_temp"]["\\2"]', '$place_array["precip"]["\\2"]', '$place_array["image"]["\\2"]', '$place_array["alt_tag"]["\\2"]', '$place_array["short_name"]["\\2"]' ); $template = preg_replace ($patterns, $replace, $template); print($template); } } ?> AND What i have done for A.C.T FORECAST... <?php //weather("A.C.T. FORECAST","http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDN10035.txt","bomonste r.htm"); weather("A.C.T. FORECAST","http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDN10035.txt","bomonste r.htm"); function weather($placename, $inputfilename, $templatefilename){ // ############################################################################ # // # BOMonster 0.1 // # Author: Matthew Cook ([EMAIL PROTECTED]) // # // # How to use: // # <$placename> is the place you want to find the forecasts for // # <$inputfilename> is the file you want to grab the data from // # <$templatefilename> is the file you want to put the forecasts into // # Details are in readme.txt // # // # Released under the GNU GPL (http://www.gnu.org/copyleft/gpl.html) // ############################################################################ # //try to connect to target - IDN10035 if(!$fp=fopen($inputfilename ,"r")) { echo "Can't Open Weather File" ; } else { //initalise $content variable $content = ""; // read content while(!feof($fp)){ $content.=fgets($fp,1024); } //close connection fclose($fp); //create new string containing data for selected place preg_match("|$Canberra.*?\\n\\n.*?\\n\\n|s", $content, $temp); //turn the first element of the temp array into a variable $temp_content = $temp[0]; //split place_content into an array by multiple spaces and single [NL]s $temp_array = preg_split ("/[\s]{2,}|[\n]/", $temp_content); //clean out all the "Min" and "Max" $temp_array = str_replace("Min", "", $temp_array); $temp_array = str_replace("Max", "", $temp_array); //trim entries for ($counter = 0; $counter <= count($temp_array)-1; $counter++){ trim($temp_array[$counter]); } //check for today's description > 80 char if (is_numeric($temp_array[3]) == FALSE){ $temp_array[2] = $temp_array[2]." ".$temp_array[3]; for ($counter = 3; $counter <= count($temp_array)-2; $counter++) { $temp_array[$counter] = $temp_array[$counter+1]; } } //print_r($temp_array); //determine if it's the afternoon/evening variant or not if (preg_match("/tonight/", $temp_array[1])){ $arvomod = 1; $temp_array = str_replace("Tonight and ", "", $temp_array); } else { $arvomod = 0; } //convert $temp_array into $place_array $place_array["name"][0] = $temp_array[0]; $place_array["name"][1] = $temp_array[1]; $place_array["name"][2] = $temp_array[6+$arvomod]; $place_array["name"][3] = $temp_array[10+$arvomod]; $place_array["name"][4] = $temp_array[14+$arvomod]; $place_array["description"][1] = $temp_array[2]; $place_array["description"][2] = $temp_array[7+$arvomod]; $place_array["description"][3] = $temp_array[11+$arvomod]; $place_array["description"][4] = $temp_array[15+$arvomod]; if ($arvomod = 1){ $place_array["min_temp"][1] = $temp_array[3]; } $place_array["min_temp"][2] = $temp_array[8+$arvomod]; $place_array["min_temp"][3] = $temp_array[12+$arvomod]; $place_array["min_temp"][4] = $temp_array[16+$arvomod]; $place_array["max_temp"][1] = $temp_array[3+$arvomod]; $place_array["max_temp"][2] = $temp_array[9+$arvomod]; $place_array["max_temp"][3] = $temp_array[13+$arvomod]; $place_array["max_temp"][4] = $temp_array[17+$arvomod]; $place_array["precip"][1] = $temp_array[5+$arvomod]; //determine the appropriate images and alt tags for ($counter = 1; $counter <= 4; $counter++){ if (stristr($place_array["description"][$counter], "thunderstorm")){ $place_array["image"][$counter] = "thunder"; $place_array["alt_tag"][$counter] = "Thunderstorms"; } elseif (stristr($place_array["description"][$counter], "shower")){ $place_array["image"][$counter] = "shower"; $place_array["alt_tag"][$counter] = "Showers"; } elseif (stristr($place_array["description"][$counter], "fine")){ $place_array["image"][$counter] = "fine"; $place_array["alt_tag"][$counter] = "Fine"; } else { $place_array["image"][$counter] = "unknown"; $place_array["alt_tag"][$counter] = "Unknown"; } } //create short names for ($counter = 0; $counter <= 4; $counter++){ $place_array["short_name"][$counter] = substr($place_array["name"][$counter], 0, 3); } } //declare template $template = ""; //open template if(!$fp=fopen($templatefilename ,"r")) { echo "Can't Open Template File" ; } else { // read template while(!feof($fp)){ $template.=fgets($fp,1024); } //close connection fclose($fp); //replace some strings $patterns = array( "/(\%Name\[)(.*?)(\]\%)/se", "/(\%Description\[)(.*?)(\]\%)/se", "/(\%Min_Temp\[)(.*?)(\]\%)/se", "/(\%Max_Temp\[)(.*?)(\]\%)/se", "/(\%Precip\[)(.*?)(\]\%)/se", "/(\%Image\[)(.*?)(\]\%)/se", "/(\%Alt_Tag\[)(.*?)(\]\%)/se", "/(\%Short_Name\[)(.*?)(\]\%)/se" ); $replace = array( '$place_array["name"]["\\2"]', '$place_array["description"]["\\2"]', '$place_array["min_temp"]["\\2"]', '$place_array["max_temp"]["\\2"]', '$place_array["precip"]["\\2"]', '$place_array["image"]["\\2"]', '$place_array["alt_tag"]["\\2"]', '$place_array["short_name"]["\\2"]' ); $template = preg_replace ($patterns, $replace, $template); print($template); } } ?> -- Cheers --------------------------------------------------------- Simon Angell Canberra ACT www.canberra-wx.com --------------------------------------------------------- Member of: Australian Severe Weather Association. www.severeweather.asn.au --------------------------------------------------------- This email is virus free. Scanned before leaving my mailbox using Norton Antivirus 2002 for Win2k Scanned with the latest definition File. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php