weather api - PHP file() function for extracting data from URL

365

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?

69

Answer

Solution:

To get data from URL:

$content = file_get_contents('http://api.openweathermap.org/data/2.5/weather?q=London,uk');

Convert it in simple array:

$new_data = json_decode($content, true);
print_r($new_data);
685

Answer

Solution:

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

People are also looking for solutions to the problem: php - Get all images in a directory except retina

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.