0

I have a problem, I have this json link on an external server:

$res = get_data('http://www.campionandoalivorno.it/iwebkit/get_giocatori1718fanta.asp' . '?fanta=' . urlencode($param1) . '&ruolo=Portiere');

The link returns the list of visible data in this url.

How can I create a php array to use the data on my page?

  • 2
    Possible duplicate of [json\_decode to array](https://stackoverflow.com/questions/5164404/json-decode-to-array) – wargre Aug 28 '17 at 17:30

2 Answers2

0

This URL returns JSON so you can use the json_decode function:

<?php

$url = file_get_contents('http://www.campionandoalivorno.it/iwebkit/get_giocatori1718fanta.asp' . '?fanta=' . urlencode($param1) . '&ruolo=Portiere');

$json = json_decode($url);

print_r($json);

And then to access the cognome in the response:

echo $json[0]->cognome;
Chris
  • 4,672
  • 13
  • 52
  • 93
0

A solution using cURL:

// create curl resource
$ch = curl_init(); // set url
curl_setopt($ch, CURLOPT_URL, "http://www.campionandoalivorno.it/iwebkit/get_giocatori1718fanta.asp?fanta=ecce&ruolo=Portiere");//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// $output contains the output string
$output = curl_exec($ch);
print_r($output); // close curl resource to free up system resources
curl_close($ch);
?>
mishamosher
  • 1,003
  • 1
  • 13
  • 28