and like us on FB

The code on this page will provide all that is necessary to render an aviation METAR or TAF report into your website with PHP or WordPress shortcode. It’s the first of a few posts that deals with different ways of dealing with aviation weather. There’s another post scheduled that deals specifically with Australian reports – both METAR/TAF reports and the ARFOR.

What is a METAR and TAF? METAR and TAF reports are weather observations written in a global format standardised by the International Civil Aviation Organization (ICAO). Aircrew and operations departments usually make fuel and other operational determinations based on the actual observation (Metar) or the short-term forecast (TAF). The area forecast includes wind information, temperature, cloud, and other weather data that assists in route planning.

If you’re using our Metar WordPress plugin, continue to use it. METAR will soon be completely rewritten to include more features than simple shortcode functions might provide.

METAR WordPress Shortcode

The result of [metar loc="klax"] will return the following report.

KLAX 191053Z 36006KT 10SM CLR 17/M05 A3005 RMK AO2 SLP174 T01671050

Available attributes are p and cache. The former if true (p=”1″) will return the result in paragraph tags (this overcomes some WP issues). The latter defines the period for which the report is cached locally. Since the reports are generally valid for an hour we cache results for 60 minutes by default.

The METAR station must be listed in the NOAA database .

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

TAF WordPress Shortcode

The result of [taf loc="kjfk"] will return the following report (I’ve included it in a blockquote).

TAF AMD KJFK 190904Z 1909/2012 20022KT 6SM SHRA BR BKN025 WS020/22050KT FM191200 25022G40KT P6SM -SHRA SCT025 BKN035 FM191500 28023G39KT P6SM BKN040 FM191900 28023G35KT P6SM SCT050 FM192300 29018G28KT P6SM SCT050 FM200600 29016G25KT P6SM FEW050

Available attributes are p and cache. The former if true (p=”1″) will return the result in paragraph tags (this overcomes some WP issues). The latter defines the period for which the report is cached locally. Since the reports are generally valid for an hour we cache results for 60 minutes by default.

The TAF station must be listed in the NOAA database .

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

PHP Functions

Used outside of WordPress, the following functions may be used. Usage of our Simple Cache plugin is required (it emulates the features of the WP transient API and avoids repeated requests to the slow NOAA server for data).

METAR

The following PHP function will return (and cache) a report for 60 minutes. Arguments are passed to the function in an array.

Usage:

TAF

The TAF function is a variation on the METAR theme. The arguments are passed to the function as an array.

Example usage (TAF for KLAX).

Returning Temperature and QNH with PHP

The WP plugin handles returning the QNH (air pressure) and temperature (although it’s in desperate need of a rewrite). Not unlike the other two PHP functions, we require the use of Simple Cache to cache the result.

Temperature

The first function simply takes the report and converts the aviation temperature format to an integer (basically, adding a minus sign).

The second function will first check for a cached temperature value. If it doesn’t exist or exceeds the cache period, it will make a request for a new valid METAR report and then parse the data for a result.

Usage is as follow:

The format of the the returned data can be altered with something like $format = '%d/%d', $format = 'T %d DP %d', $format = 'Temperature: %d', etc.

Use $unit = 0 to return Fahrenheit.

QNH (Altimeter)

The hectopascal (hPa) QNH is returned in most parts of the world. The USA, however, is stuck in its little imperial vacuum and still uses the archaic inches of mercury to measure pressure. Both values are returned by our function.

Usage is as follows:

Considerations

  • We previously provided versions of this code on a few websites. However, this proved problematic with updates and other revisions. All other posts will now redirect to BeliefMedia for up-to-date code.
  • Our WordPress plugin is in desperate need of an update (and it is forthcoming). It was submitted to WP because of a need at the time.
  • Other information can be extracted from either report (wind, cloud etc). The next update to our plugin should include these features.
  • Our client platform manages aviation weather. It’s a default module… whether you want it or not. The system provides an API to graph changes in reports (dating back several years).

Download

Note: The WordPress plugin will soon get a substantial update.

Plugin Title: Metar Author: beliefmedia
Description: Metar is a plugin that includes global (and all Australian) aviation METAR or TAF reports, or…
Download (downloaded 1,973 times) | Plugin Page

Title: Aviation METAR and TAF Reports
Description: Aviation METAR or TAF Reports with PHP or WordPress Shortcode.
Download: Shortcode (V0.3) | PHP Code (V0.3) | Plugin Page

Shortt URL for this post: http://shor.tt/A5m