-1

I am trying to pull fixtures data from Fantasy Premier League API. But i am stuck. I received string data instead of JSON data. It's been while since i used PHP, as i am more focused in JavaScript these days. Please guide me.

<?php
 $arrContextOptions=array(
            "ssl"=>array(
                "verify_peer"=>false,
                "verify_peer_name"=>false,
            ),
        );
        $url = "https://fantasy.premierleague.com/api/fixtures/?event=1";
        $response = file_get_contents($url, false, stream_context_create($arrContextOptions));
        // echo $response;

         $events  = json_encode($response, true);
         print_r($events);
         ?>

Variable $events gives me string instead array. It's because API is giving data in string format or i am doing something wrong.

enter image description here

Any help will be much appreciated. Thank You

Sujan Shrestha
  • 1,020
  • 1
  • 18
  • 32

1 Answers1

0

I believe you confused between json-encode and json-decode,

json-encode, the function you using take object and convert it to string - so having $events as string is the expected behavior.

json-decode on the other hand, take string and convrt it to object - so you should use that as:

$events  = json_decode($response, true);
dWinder
  • 11,597
  • 3
  • 24
  • 39