I am trying to parse this JSONP file. I have had some luck with parsing JSON in the past and this is the first time I have tried JSONP. I read on some other threads on this site that you can use substr()
to get the data by stripping off the JavaScript function call. This is my attempt:
<?php
$json = file_get_contents("http://live.nhle.com/GameData/GCScoreboard/2016-01-18.jsonp");
$json = json_decode(substr($json, 15, 1));
echo var_dump($json);
$date = strtotime("now");
echo $date;
foreach ($json as $d) {
$atCommon = $d['atcommon'];
$idGame = $d['id'];
$caNationalBroadcasts = $d['canationalbroadcasts'];
$ata = $d['ata'];
$r1 = $d['r1'];
$atsog = $d['atsog'];
$bs = $d['bs'];
$htCommon = $d['htcommon'];
$atn = $d['atn'];
$hts = $d['hts'];
$atc = $d['atc'];
$htn = $d['htn'];
$usNationalBroadcasts = $d['usnationalbroadcasts'];
$gcl = $d['gcl'];
$hta = $d['hta'];
$ats = $d['ats'];
$htc = $d['htc'];
$htsog = $d['htsog'];
$bsc = $d['bsc'];
$gs = $d['gs'];
$gcl1 = $d['gcl1'];
// echo $htCommon;
// echo $atCommon;
}
?>
So far the I get these two errors:
WARNING file_get_contents() has been disabled for security reasons on line number 2
WARNING Invalid argument supplied for foreach() on line number 7
Also, I know file_get_contents()
is not disabled because I am using that function in multiple other places on my project *link below.
Here is my current output (which is null for the JSONP):
NULL 1453102048 The Null and $date are hidden echo's beneath the stats link
The question is basically this...What am I doing wrong?