php:parse_the_noaa_space_weather_data_in_php
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
php:parse_the_noaa_space_weather_data_in_php [2019/05/20 10:18] – genadmin | php:parse_the_noaa_space_weather_data_in_php [2019/08/01 11:37] (current) – genadmin | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <code php> | ||
+ | function getSpaceWeather() { | ||
+ | $url = " | ||
+ | $ch = curl_init(); | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | $response = curl_exec($ch); | ||
+ | | ||
+ | curl_close($ch); | ||
+ | $data = json_decode($response); | ||
+ | $sr=(array) $data[0]; // Cast the JSON object into an array | ||
+ | |||
+ | $html=" | ||
+ | $html.=" | ||
+ | $html.=" | ||
+ | $html.=" | ||
+ | $html.=" | ||
+ | $html.=" | ||
+ | |||
+ | return $html; // return back the HTML | ||
+ | }</ | ||
+ | |||
+ | This API is really easy to use, and returns a 3 day window for C, M and X Class as well as 10mev and 100mev proton readings. The data is returned from the API and dumped into an Array() so you can easily change the output. | ||
+ | |||
+ | In its default config (above) it returns HTML, but can easily be changed to return the $sr array by removing the $html... lines and changing the return $html; to be return $sr; | ||
+ | |||
+ | * $sr[" | ||
+ | * $sr[" | ||
+ | * $sr[" | ||
+ | * $sr[" | ||
+ | * $sr[" | ||
+ | * $sr[" | ||
+ | |||
+ | <code php>echo getSpaceWeather();</ |