[PHP] Re: Need some help please.

2002-09-18 Thread Simon Angell

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(
 

[PHP] Re: Need some help please.

2002-09-18 Thread Simon Angell


I Have now got it kinda working, but not fully, i changed something i
shouldn't have, but fixed that..
 //create new string containing data for selected place
  preg_match(|$placename.*?\\n\\n.*?\\n\\n|s, $content, $temp); (i had it
//create new string containing data for selected place
  preg_match(|$canberra.*?\\n\\n.*?\\n\\n|s, $content, $temp); by
accident), but as you see it doesn't get all the forecast
Mildura (works)
http://www.canberra-wx.com/bomonster/bomonster01.php
Canberra (kinda works)
http://www.canberra-wx.com/bomonster/bomonster1.php

The Problem now is displaying the full description of the forecast and the
forecast temps for the next few days...also noticed that the Mildura
Forecast is not fully displayed, it is missing 1 work at the end of the
forecast description...

So How do i change the php to display the Whole description and the next few
days of temps.
Remember the layout of the source of the info is different
http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV17001.txt is the Mildura
forecast...
http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDN10035.txt is the Canberra/A.C.T
Forecast that i want to use.

--
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.

Simon Angell [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hi.

 I am having trouble with a PHP script. I am not the one who made this and
my
 knowledge on php is very little.
 I came across this php script
www.canberra-wx.com/bomonster/bomonster01.php
 which is weather forecasting for a place called Mildura.
 The file that the PHP gets its info from is here...
 http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV17001.txt and if you look
down
 the page you will see the Mildura forecast that the PHP draws its info
 output from.

 My Problem is that i want it to work for this file...
 http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDN10035.txt and i cant work out
 how to get it going.
 i have got this far www.canberra-wx.com/bomonster/bomonster1.php (look at
 the code, the actual outpot doesn't work..thats my problem). The part I
want
 the PHP to do its info output is from A.C.T FORECAST (like from the
Mildura
 in IDV17001.txt)

 Any help on how to get it to work would be great.

 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