PHP code example of safran-cassiopee / php-metar-decoder

1. Go to this page and download the library: Download safran-cassiopee/php-metar-decoder 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/ */

    

safran-cassiopee / php-metar-decoder example snippets








der = new MetarDecoder\MetarDecoder();
$d = $decoder->parse('METAR LFPO 231027Z AUTO 24004G09MPS 2500 1000NW R32/0400 R08C/0004D +FZRA VCSN //FEW015 17/10 Q1009 REFZRA WS R03')

//context information
$d->isValid(); //true
$d->getRawMetar(); //'METAR LFPO 231027Z AUTO 24004G09MPS 2500 1000NW R32/0400 R08C/0004D +FZRA VCSN //FEW015 17/10 Q1009 REFZRA WS R03'
$d->getType(); //'METAR'
$d->getIcao(); //'LFPO'
$d->getDay(); //23
$d->getTime(); //'10:27 UTC'
$d->getStatus(); //'AUTO'

//surface wind
$sw = $d->getSurfaceWind(); //SurfaceWind object
$sw->getMeanDirection()->getValue(); //240
$sw->getMeanSpeed()->getValue(); //4
$sw->getSpeedVariations()->getValue(); //9
$sw->getMeanSpeed()->getUnit(); //'m/s'

//visibility
$v = $d->getVisibility(); //Visibility object
$v->getVisibility()->getValue(); //2500
$v->getVisibility()->getUnit(); //'m'
$v->getMinimumVisibility()->getValue(); //1000
$v->getMinimumVisibilityDirection(); //'NW'
$v->hasNDV(); //false

//runway visual range
$rvr = $d->getRunwaysVisualRange(); //RunwayVisualRange array
$rvr[0]->getRunway(); //'32'
$rvr[0]->getVisualRange()->getValue(); //400
$rvr[0]->getPastTendency(); //''
$rvr[1]->getRunway(); //'08C'
$rvr[1]->getVisualRange()->getValue(); //4
$rvr[1]->getPastTendency(); //'D'

//present weather
$pw = $d->getPresentWeather(); //WeatherPhenomenon array
$pw[0]->getIntensityProximity(); //'+'
$pw[0]->getCharacteristics(); //'FZ'
$pw[0]->getTypes(); //array('RA')
$pw[1]->getIntensityProximity(); //'VC'
$pw[1]->getCharacteristics(); //null
$pw[1]->getTypes(); //array('SN')

// clouds
$cld = $d->getClouds(); //CloudLayer array
$cld[0]->getAmount(); //'FEW'
$cld[0]->getBaseHeight()->getValue(); //1500
$cld[0]->getBaseHeight()->getUnit(); //'ft'

// temperature
$d->getAirTemperature()->getValue(); //17
$d->getAirTemperature()->getUnit(); //'deg C'
$d->getDewPointTemperature()->getValue(); //10

// pressure
$d->getPressure()->getValue(); //1009
$d->getPressure()->getUnit(); //'hPa'

// recent weather
$rw = $d->getRecentWeather();
$rw->getCharacteristics(); //'FZ'
$rw->getTypes(); //array('RA')

// windshears
$d->getWindshearRunways(); //array('03')


// check that the $dew_point is not null and give it a default value if it is
$dew_point = $d->getDewPointTemperature();
if($dew_point == null){
    $dew_point = new Value(999, Value::DEGREE_CELSIUS);
}

// $dew_point object can now be accessed safely
$dew_point->getValue();
$dew_point->getUnit();

// speed units:
Value::METER_PER_SECOND
Value::KILOMETER_PER_HOUR
Value::KNOT

// distance units:
Value::METER
Value::FEET
Value::STATUTE_MILE

// pressure units:
Value::HECTO_PASCAL
Value::MERCURY_INCH

// use on-the-fly conversion
$distance_in_sm = $visibility->getConvertedValue(Value::STATUTE_MILE);
$speed_kph = $speed->getConvertedValue(Value::KILOMETER_PER_HOUR);



$decoder = new MetarDecoder\MetarDecoder();

// change global parsing mode to "strict"
$decoder->setStrictParsing(true);

// this parsing will be made with strict mode
$decoder->parse("...");

// but this one will ignore global mode and will be made with not-strict mode anyway
$decoder->parseNotStrict("...");

// change global parsing mode to "not-strict"
$decoder->setStrictParsing(false);

// this parsing will be made with no-strict mode
$decoder->parse("...");

// but this one will ignore global mode and will be made with strict mode anyway
$decoder->parseStrict("...");

json
{
    "afran-cassiopee/php-metar-decoder": "dev-master"
    }
}
shell
git clone https://github.com/<username>/php-metar-decoder