This is the JSON i am trying to decode with PHP, but getting issues. Please check my code below.
{ "146505212039213_2962095710480135": {
"reactions_like": {
"data": [
],
"summary": {
"total_count": 172595
}
},
"reactions_love": {
"data": [
],
"summary": {
"total_count": 75252
}
},
"reactions_haha": {
"data": [
],
"summary": {
"total_count": 132
}
},
"id": "146505212039213_2962095710480135"
}}
Code i am using:
function curl_get_contents($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$json = curl_get_contents('URL HERE');
$data = json_decode($json);
echo $data->146505212039213_2962095710480135->reactions_like->summary->total_count;
This is the error i am getting:
Parse error: syntax error, unexpected '146505212039213' (T_DNUMBER), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C:\xampp\htdocs\test.php on line 13
What i am doing wrong here?