0

I've been struggling with a curlopt response for quite some time now and I hope you guys can give me some pointers.

If you please visit the following page: https://niarthgin.com/api/result.php

This will generate a simple response using curlopt. Here is the code that I have used in order to get these results:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://www.bungie.net/Platform/Destiny2/SearchDestinyPlayer/2/Niarthgin/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "postman-token: xxxx",
    "x-api-key: xxxx"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
      echo "cURL Error #:" . $err;
} else {
    echo $response;

}
?>

I want to break down that response but I have no idea how to do it. For example, in that response, you have a MembershipType a displayName etc. How can I parse the response individually? Like I know I can parse the response with json.parse() but that will only parse a given string. I want to be able to parse the response in segments ..

Thanks for reading! :)

Sam
  • 2,856
  • 3
  • 18
  • 29
  • 1
    json_decode($response,true); This will give you an array use print_r($array) to see what the structure is. – Dieter Kräutl Sep 18 '18 at 13:11
  • Possible duplicate of [How do I extract data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php) – MonkeyZeus Sep 18 '18 at 13:13
  • I tried using json_decode but I get no results? $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } $raw = $response; $decode = json_decode($raw); echo $decode; – user10380489 Sep 18 '18 at 13:56

0 Answers0