Jump to content

You're browsing the 2004-2023 VATSIM Forums archive. All content is preserved in a read-only fashion.
For the latest forum posts, please visit https://forum.vatsim.net.

Need to find something? Use the Google search below.
PLEASE READ - Webmaster Support Forum
This forum will be retired in the near future. Please direct all queries to our dedicated GitHub support page https://github.com/vatsimnetwork/developer-info/discussions 
Here you can find documentation on our services and we are continuing to migrate pertinent information into the Wiki pages https://github.com/vatsimnetwork/developer-info/wiki

php code for getting metars


Mark Foister
 Share

Recommended Posts

Mark Foister
Posted
Posted

Hi there,

 

I can't seem to fine the whole code in php to gather metars ?

 

Is it possible for someone to share there code please.

 

It would be very much appreciated

 

Kind Regards

Link to comment
Share on other sites

Anthony Lawrence
Posted
Posted
Hi there,

 

I can't seem to fine the whole code in php to gather metars ?

 

Is it possible for someone to share there code please.

 

It would be very much appreciated

 

Kind Regards

 

Hi Mark,

 

The basic principle is that you want to get the contents of a remote URL (thee VATSIM metar tool). Two possible (basic) ways:

 

<?php

$metar = file_get_contents("http://metar.vatsim.net/metar.php?id=EGLL");

?>

 

<?php

$metar = file("http://metar.vatsim.net/metar.php?id=EGLL");
$metar = isset($metar[0]) ? $metar[0] : "No metar";

?>

 

They are both basic and have no error checking / exception handling, but it's enough to get you started for now.

 

A.

0
Link to comment
Share on other sites

Luca Benelli
Posted
Posted

Keep in mind that our metars don't change more than once every 15 minutes... so cache the results for a while.

Luca Benelli - C3 - P2

Link to comment
Share on other sites

Mark Foister
Posted
Posted

Cheers guys !!

Link to comment
Share on other sites

Luca Benelli
Posted
Posted

Depending on the number of requests, if you need LOTS of airports consider fetching the whole file

 

http://metar.vatsim.net/metar.php?id=all

 

Again, consider what you fetch and how often basing on what you really need.

 

Luca

Luca Benelli - C3 - P2

Link to comment
Share on other sites

Mark Foister
Posted
Posted
Depending on the number of requests, if you need LOTS of airports consider fetching the whole file

 

http://metar.vatsim.net/metar.php?id=all

 

Again, consider what you fetch and how often basing on what you really need.

 

Luca

 

I have inputted the code but nothing shows up on the site ??

Link to comment
Share on other sites

Luca Benelli
Posted
Posted

If you click the link do you see the metar info in your browser?

Luca Benelli - C3 - P2

Link to comment
Share on other sites

Mark Foister
Posted
Posted
If you click the link do you see the metar info in your browser?

 

 

I see the metar yeah but it doesn't show it on the site :/

Link to comment
Share on other sites

Luca Benelli
Posted
Posted

Then you probably have something wrong in your code....

 

have you put an echo of some sorts in there? the code you have been given is only a basic fetch of the metar....

Luca Benelli - C3 - P2

Link to comment
Share on other sites

Mark Foister
Posted
Posted
Then you probably have something wrong in your code....

 

have you put an echo of some sorts in there? the code you have been given is only a basic fetch of the metar....

 

It don't matter now i have done it

 

Thanks for the help tho

Link to comment
Share on other sites

 Share