Search code examples
phpweather-api

PHP file() function for extracting data from URL


Although this may seem like a general question, how can you extract content from a URL such as (http://api.openweathermap.org/data/2.5/weather?q=London,uk) so that it can be formatted and used in the form of an array for each element in PHP? More specifically, how can I extract information from websites in general?


Solution

  • $json = file_get_contents('http://api.openweathermap.org/data/2.5/weather?q=London,uk');
    $array = json_decode($json, true);
    var_dump($array);