I am trying to create a simple PHP script which will look at a METAR report and get the first cloud cover condition whenever the PHP script is launched. What I need is a way to search for the first word out of these:
BKN, CAVOK, CLR, FEW, NSC, OVC, SCT, SKC, VV
Sometimes the METAR report will have several cloud conditions with the first being that closest to the ground. I need just the first match to become a variable.
Say this is the current METAR report:
2013/12/28 21:51 KORD 282151Z 21012G21KT 10SM FEW250 NSC900 09/M01 A2992 RMK AO2 SLP136 T00941006
So both FEW and NSC are in that METAR report. I need the variable to be something like $metar = "FEW"; for the variable and nothing else. The other problem is doing it as an array may not work as the codes I need may be at $metars[7] and later could be at $metars[5] or elsewhere in the array.
This is the code I have so far, but I cannot figure out how to do what I need it to do:
<?php
$station = "KORD";// Enter your airport's code here.
$metarwx = "http://weather.noaa.gov/pub/data/observations/metar/stations/$station.TXT";
$metars = file_get_contents($metarwx);
print_r(explode(" ", $metars));
?>
Thanks in advance for any help!