Page 245 - Asterisk™: The Future of Telephony
P. 245

elseif (preg_match("/<wind_dir>Northwest<\/wind_dir>/i",$weatherPage))
                   {
                       $currentWindDirection='northwesterly';
                   }
                   elseif (preg_match("/<wind_dir>Northeast<\/wind_dir>/i",$weatherPage))
                   {
                       $currentWindDirection='northeasterly';
                   }
                   elseif (preg_match("/<wind_dir>Southwest<\/wind_dir>/i",$weatherPage))
                   {
                       $currentWindDirection='southwesterly';
                   }
                   elseif (preg_match("/<wind_dir>Southeast<\/wind_dir>/i",$weatherPage))
                   {
                       $currentWindDirection='southeasterly';
                   }
               The wind direction is found through the use of preg_match (located in the wind_dir tags)
               and is assigned to the variable $currentWindDirection.
                   #grab wind speed
                   if (preg_match("/<wind_mph>([0-9.]+)<\/wind_mph>/i",$weatherPage,$matches))
                   {
                       $currentWindSpeed = $matches[1];
                   }
               Finally, we’ll grab the current wind speed and assign it to the $currentWindSpeed vari-
               able.
                   # tell the caller the current conditions
                   if ($currentTemp)
                   {
                       fwrite(STDOUT,"STREAM FILE temperature \"\"\n");
                       fflush(STDOUT);
                       $result = trim(fgets(STDIN,4096));
                       checkresult($result);
                       fwrite(STDOUT,"STREAM FILE is \"\"\n");
                       fflush(STDOUT);
                       $result = trim(fgets(STDIN,4096));
                       checkresult($result);
                       fwrite(STDOUT,"SAY NUMBER $currentTemp \"\"\n");
                       fflush(STDOUT);
                       $result = trim(fgets(STDIN,4096));
                       checkresult($result);
                       fwrite(STDOUT,"STREAM FILE degrees \"\"\n");
                       fflush(STDOUT);
                       $result = trim(fgets(STDIN,4096));
                       checkresult($result);
                       fwrite(STDOUT,"STREAM FILE fahrenheit \"\"\n");
                       fflush(STDOUT);
                       $result = trim(fgets(STDIN,4096));
                       checkresult($result);
                   }

                   if ($currentWindDirection && $currentWindSpeed)
                   {


                                                                   Creating AGI Scripts in PHP | 217
   240   241   242   243   244   245   246   247   248   249   250