PHP code example of jamesmorrison / metar

1. Go to this page and download the library: Download jamesmorrison/metar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jamesmorrison / metar example snippets


use JamesMorrison\Metar\Parser;

$metar = new Parser('METAR EGLL 141250Z 24015G25KT 9999 FEW040CB 12/08 Q1015 NOSIG');

$metar->station->icao;               // 'EGLL'
$metar->observationTime->day;        // 14
$metar->observationTime->hour;       // 12
$metar->observationTime->minute;     // 50

$metar->wind->direction;             // 240
$metar->wind->speed;                 // 15
$metar->wind->gusts;                 // 25
$metar->wind->unit;                  // WindUnit::Knots
$metar->wind->speedKnots;            // 15.0
$metar->wind->speedMps;              // 7.7

$metar->visibility->distance;        // 9999.0
$metar->visibility->unit;            // VisibilityUnit::Metres

$metar->clouds[0]->amount;           // CloudAmount::Few
$metar->clouds[0]->height;           // 4000
$metar->clouds[0]->type;             // CloudType::Cumulonimbus

$metar->temperature->temperature;    // 12
$metar->temperature->dewpoint;       // 8

$metar->pressure->hectopascals;      // 1015.0
$metar->pressure->inchesOfMercury;   // 29.97

$metar->wind->label();       // 'Wind from 240 degrees at 15 knots gusting 25 knots'
$metar->pressure->label();   // '1015 hPa / 29.97 inHg'
echo $metar->temperature;    // 'Temperature 12°C (54°F), dewpoint 8°C (46°F)'

// Full METAR summary
echo $metar->label();

json_encode($metar, JSON_PRETTY_PRINT);

$metar = new Parser('METAR EGLL 141250Z 24015KT CAVOK 12/08 Q1015');
$metar->cavok; // true

$metar = new Parser('METAR KJFK 141250Z 24015KT 10SM FEW040 12/08 A2997 RMK AO2 SLP153 T01170083');

foreach ($metar->remarks->groups as $remark) {
    echo $remark->label() . "\n";
}