I am sending a cURL request to an API which returns this response:
string(826) "HTTP/1.1 200
Server: openresty/1.13.6.2
Date: Sat, 20 Oct 2018 18:21:54 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 562
Connection: keep-alive
Expires: Sat, 20 Oct 2018 21:20:26 UTC
Cache-Control: max-age=10800
X-Cache-Status: HIT
{
"SearchResponse": {
"Matches": {
"SearchMatch": [
{
"Id": "43000173601",
"Lat": 52.4770035488100035,
"Lon": -1.71806745583999998,
"Name": "Yorkminster Drive",
"Modes": {
"Mode": "BUS_OR_COACH"
},
"TopMostParentId": "430G01736"
},
{
"Id": "43000173602",
"Lat": 52.4776389831399968,
"Lon": -1.71687080637,
"Name": "Yorkminster Drive",
"Modes": {
"Mode": "BUS_OR_COACH"
},
"TopMostParentId": "430G01736"
}
]
},
"Query": "yorkminster",
"Total": 2
}
}
I want to json_decode()
the JSON response but have no clue how to get the JSON part and ignore the annoying top part. I have tried using explode()
but that put it into more pieces than my head could handle, any ideas would be helpful.
Here is my cURL request:
curl_init('api url');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
$response = curl_exec($ch);
curl_close($ch);