📄 phpweather.php
字号:
$decoded_metar['visibility_miles'] = '>6.2'; $decoded_metar['visibility_km'] = '>10'; } elseif(ereg('^([0-9]{4})$', $part, $regs)) { /* * Visibility in meters (4 digits only) */ $decoded_metar['visibility_km'] = number_format($regs[1]/1000, 1); $decoded_metar['visibility_miles'] = number_format( ($regs[1]/1000) / 1.609344, 1); } elseif (ereg('^[0-9]$', $part)) { /* * Temp Visibility Group, single digit followed by space */ $temp_visibility_miles = $part; } elseif (ereg('^M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$', $temp_visibility_miles . ' ' . $parts[$i], $regs)) { /* * Visibility Group */ if ($regs[4] == '/') { $vis_miles = $regs[2] + $regs[3]/$regs[5]; } else { $vis_miles = $regs[1]; } if ($regs[0][0] == 'M') { /* The visibility measured in miles, prefixed with < to indicate 'Less than' */ $decoded_metar['visibility_miles'] = '<' . number_format($vis_miles, 1); /* The visibility measured in kilometers. The value is rounded to one decimal place, prefixed with < to indicate 'Less than' */ $decoded_metar['visibility_km'] = '<' . number_format($vis_miles * 1.609344, 1); } else { /* The visibility measured in mile.s */ $decoded_metar['visibility_miles'] = number_format($vis_miles, 1); /* The visibility measured in kilometers, rounded to one decimal place. */ $decoded_metar['visibility_km'] = number_format($vis_miles * 1.609344, 1); } } elseif ($part == 'CAVOK') { /* CAVOK: Used when the visibility is greather than 10 kilometers, the lowest cloud-base is at 5000 feet and there is no significant weather. */ $decoded_metar['visibility_km'] = '>10'; $decoded_metar['visibility_miles'] = '>6.2'; $decoded_metar['cloud_layer1_condition'] = 'CAVOK'; } elseif (ereg('^R([0-9][0-9][RLC]?)/([MP]?[0-9]{4})V?(P?[0-9]{4})?F?T?$', $part, $regs)) { $decoded_metar['runway_nr'] = $regs[1]; if ($regs[3]) { /* We have both min and max visibility. */ $prefix = ''; if ($regs[2][0] == 'M') { /* Less than. */ $prefix = '<'; $regs[2] = substr($regs[2], 1); } $decoded_metar['runway_vis_min_ft'] = $prefix . number_format($regs[2]); $decoded_metar['runway_vis_min_meter'] = $prefix . number_format($regs[2] * 0.3048); $prefix = ''; if ($regs[3][0] == 'P') { /* Greather than. */ $prefix = '>'; $regs[3] = substr($regs[3], 1); } $decoded_metar['runway_vis_max_ft'] = $prefix . number_format($regs[3]); $decoded_metar['runway_vis_max_meter'] = $prefix . number_format($regs[3] * 0.3048); } else { /* We only have a single visibility. */ $prefix = ''; if ($regs[2][0] == 'M') { $prefix = '<'; $regs[2] = substr($regs[2], 1); } elseif ($regs[2][0] == 'P') { $prefix = '>'; $regs[2] = substr($regs[2], 1); } $decoded_metar['runway_vis_ft'] = $prefix . number_format($regs[2]); $decoded_metar['runway_vis_meter'] = $prefix . number_format($regs[2] * 0.3048); } } elseif (ereg('^(-|\+|VC)?(TS|SH|FZ|BL|DR|MI|BC|PR|RA|DZ|SN|SG|GR|' . 'GS|PE|IC|UP|BR|FG|FU|VA|DU|SA|HZ|PY|PO|SQ|FC|SS|DS)+$', $part)) { /* * Current weather-group */ if ($part[0] == '-') { /* A light phenomenon */ $decoded_metar['weather'] .= $strings['light']; $part = substr($part, 1); } elseif ($part[0] == '+') { /* A heavy phenomenon */ $decoded_metar['weather'] .= $strings['heavy']; $part = substr($part, 1); } elseif ($part[0].$part[1] == 'VC') { /* Proximity Qualifier */ $decoded_metar['weather'] .= $strings['nearby']; $part = substr($part, 2); } else { /* no intensity code => moderate phenomenon */ $decoded_metar['weather'] .= $strings['moderate']; } while ($bite = substr($part, 0, 2)) { /* Now we take the first two letters and determine what they mean. We append this to the variable so that we gradually build up a phrase. */ $decoded_metar['weather'] .= $weather_array[$bite]; /* Here we chop off the two first letters, so that we can take a new bite at top of the while-loop. */ $part = substr($part, 2); } } elseif (ereg('(SKC|CLR)', $part, $regs)) { /* * Cloud-layer-group. * There can be up to three of these groups, so we store them as * cloud_layer1, cloud_layer2 and cloud_layer3. */ $cloud_layers++; /* Again we have to translate the code-characters to a meaningful string. */ $decoded_metar['cloud_layer'. $cloud_layers.'_condition'] = $cloud_condition_array[$regs[1]]; $decoded_metar['cloud_layer'.$cloud_layers.'_coverage'] = $cloud_coverage[$regs[1]]; } elseif (ereg('^(VV|FEW|SCT|BKN|OVC)([0-9]{3})(CB|TCU)?$', $part, $regs)) { /* We have found (another) a cloud-layer-group. There can be up to three of these groups, so we store them as cloud_layer1, cloud_layer2 and cloud_layer3. */ $cloud_layers++; /* Again we have to translate the code-characters to a meaningful string. */ if ($regs[1] == 'OVC') { $clouds_str_temp = ''; } else { $clouds_str_temp = $strings['clouds']; } if ($regs[3] == 'CB') { /* cumulonimbus (CB) clouds were observed. */ $decoded_metar['cloud_layer'.$cloud_layers.'_condition'] = $cloud_condition_array[$regs[1]] . $strings['clouds_cb']; } elseif ($regs[3] == 'TCU') { /* towering cumulus (TCU) clouds were observed. */ $decoded_metar['cloud_layer'.$cloud_layers.'_condition'] = $cloud_condition_array[$regs[1]] . $strings['clouds_tcu']; } else { $decoded_metar['cloud_layer'.$cloud_layers.'_condition'] = $cloud_condition_array[$regs[1]] . $clouds_str_temp; } $decoded_metar['cloud_layer'.$cloud_layers.'_coverage'] = $cloud_coverage[$regs[1]]; $decoded_metar['cloud_layer'.$cloud_layers.'_altitude_ft'] = $regs[2] *100; $decoded_metar['cloud_layer'.$cloud_layers.'_altitude_m'] = round($regs[2] * 30.48); } elseif (ereg('^(M?[0-9]{2})/(M?[0-9]{2})?$', $part, $regs)) { /* * Temperature/Dew Point Group * The temperature and dew-point measured in Celsius. */ $decoded_metar['temp_c'] = number_format(strtr($regs[1], 'M', '-')); $decoded_metar['dew_c'] = number_format(strtr($regs[2], 'M', '-')); /* The temperature and dew-point measured in Fahrenheit, rounded to the nearest degree. */ $decoded_metar['temp_f'] = round(strtr($regs[1], 'M', '-') * (9/5) + 32); $decoded_metar['dew_f'] = round(strtr($regs[2], 'M', '-') * (9/5) + 32); } elseif(ereg('A([0-9]{4})', $part, $regs)) { /* * Altimeter * The pressure measured in inHg */ $decoded_metar['altimeter_inhg'] = number_format($regs[1]/100, 2); /* The pressure measured in mmHg, hPa and atm */ $decoded_metar['altimeter_mmhg'] = number_format($regs[1] * 0.254, 1); $decoded_metar['altimeter_hpa'] = number_format($regs[1] * 0.33863881578947); $decoded_metar['altimeter_atm'] = number_format($regs[1] * 3.3421052631579e-4, 3); } elseif(ereg('Q([0-9]{4})', $part, $regs)) { /* * Altimeter * This is strange, the specification doesnt say anything about * the Qxxxx-form, but it's in the METARs. */ /* The pressure measured in hPa */ $decoded_metar['altimeter_hpa'] = number_format($regs[1]); /* The pressure measured in mmHg, inHg and atm */ $decoded_metar['altimeter_mmhg'] = number_format($regs[1] * 0.7500616827, 1); $decoded_metar['altimeter_inhg'] = number_format($regs[1] * 0.0295299875, 2); $decoded_metar['altimeter_atm'] = number_format($regs[1] * 9.869232667e-4, 3); } elseif (ereg('^T([0-9]{4})([0-9]{4})', $part, $regs)) { /* * Temperature/Dew Point Group, coded to tenth of degree. * The temperature and dew-point measured in Celsius. */ store_temp($regs[1],$decoded_metar,'temp_c','temp_f'); store_temp($regs[2],$decoded_metar,'dew_c','dew_f'); } elseif (ereg('^T([0-9]{4}$)', $part, $regs)) { store_temp($regs[1],$decoded_metar,'temp_c','temp_f'); } elseif (ereg('^1([0-9]{4}$)', $part, $regs)) { /* * 6 hour maximum temperature Celsius, coded to tenth of degree */ store_temp($regs[1],$decoded_metar,'temp_max6h_c','temp_max6h_f'); } elseif (ereg('^2([0-9]{4}$)', $part, $regs)) { /* * 6 hour minimum temperature Celsius, coded to tenth of degree */ store_temp($regs[1],$decoded_metar,'temp_min6h_c','temp_min6h_f'); } elseif (ereg('^4([0-9]{4})([0-9]{4})$', $part, $regs)) { /* * 24 hour maximum and minimum temperature Celsius, coded to * tenth of degree */ store_temp($regs[1],$decoded_metar,'temp_max24h_c','temp_max24h_f'); store_temp($regs[2],$decoded_metar,'temp_min24h_c','temp_min24h_f'); } elseif(ereg('^P([0-9]{4})', $part, $regs)) { /* * Precipitation during last hour in hundredths of an inch * (store as inches) */ $decoded_metar['precip_in'] = number_format($regs[1]/100, 2); $decoded_metar['precip_mm'] = number_format($regs[1]*0.254, 2); } elseif(ereg('^6([0-9]{4})', $part, $regs)) { /* * Precipitation during last 3 or 6 hours in hundredths of an * inch (store as inches) */ $decoded_metar['precip_6h_in'] = number_format($regs[1]/100, 2); $decoded_metar['precip_6h_mm'] = number_format($regs[1]*0.254, 2); } elseif(ereg('^7([0-9]{4})', $part, $regs)) { /* * Precipitation during last 24 hours in hundredths of an inch * (store as inches) */ $decoded_metar['precip_24h_in'] = number_format($regs[1]/100, 2); $decoded_metar['precip_24h_mm'] = number_format($regs[1]*0.254, 2); } elseif(ereg('^4/([0-9]{3})', $part, $regs)) { /* * Snow depth in inches */ $decoded_metar['snow_in'] = number_format($regs[1]); $decoded_metar['snow_mm'] = number_format($regs[1] * 25.4); } else { /* * If we couldn't match the group, we assume that it was a * remark. */ $decoded_metar['remarks'] .= ' ' . $part; } } /* * Relative humidity */ $decoded_metar['rel_humidity'] = number_format(pow(10, (1779.75 * ($decoded_metar['dew_c'] - $decoded_metar['temp_c'])/ ((237.3 + $decoded_metar['dew_c']) * (237.3 + $decoded_metar['temp_c'])) + 2)), 1); /* * Humidity index */ $e = 6.112 * pow(10, 7.5 * $decoded_metar['temp_c'] / (237.7 + $decoded_metar['temp_c'])) * $decoded_metar['rel_humidity']/100; $decoded_metar['humidex_c'] = number_format($decoded_metar['temp_c'] + 5/9 * ($e - 10),1); $decoded_metar['humidex_f'] = number_format($decoded_metar['humidex_c'] * 9/5 + 32, 1); /* * Windchill. * * This is only appropriate if temp < 40f and windspeed > 3 mph */ if ($decoded_metar['temp_f'] <= '40' && $decoded_metar['wind_miles_per_hour'] > '3'){ $decoded_metar['windchill_f'] = number_format(35.74 + 0.6215 * $decoded_metar['temp_f'] - 35.75 * pow((float)$decoded_metar['wind_miles_per_hour'], 0.16) + 0.4275 * $decoded_metar['temp_f'] * pow((float)$decoded_metar['wind_miles_per_hour'],0.16)); $decoded_metar['windchill_c'] = number_format(13.112 + 0.6215 * $decoded_metar['temp_c'] - 13.37 * pow(($decoded_metar['wind_miles_per_hour']/1.609), 0.16) + 0.3965 * $decoded_metar['temp_c'] * pow(($decoded_metar['wind_miles_per_hour']/1.609),0.16)); } return $decoded_metar;} ?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -