Reputation: 9086
I tried a lot scripts and none of them worked.
This is the code I have:
$contents = file_get_contents("http://video.foxnews.com/v/feed/video/1228085488001.js");
var_dump(json_decode($contents, true));
It outputs:
array(2) { ["@attributes"]=> array(1) { ["version"]=> string(3) "2.0" } ["channel"]=> array(2) { ["title"]=> array(0) { } ["item"]=> array(2) { ["title"]=> string(49) "Should Government Stay Out of Foreclosure Crisis?" ["media-content"]=> array(32) { ["@attributes"]=> array(1) { ["url"]=> string(60) "http://media2.foxnews.com/102011/ff_massi_102011_FNC_MED.mp4" } ["media-player"]=> array(1) { ["@attributes"]=> array(1) { ["url"]=> string(91) "http://video.foxnews.com/assets/video-player.swf?video_id=1228085488001&d=video.foxnews.com" } } ["media-description"]=> string(39) "Real estate expert Bob Massi sounds off" ["media-thumbnail"]=> string(70) "http://video.foxnews.com/thumbnails/102011/640/360/ff_massi_102011.jpg" ["media-keywords"]=> array(0) { } ["media-credit"]=> string(16) "foxnews1-foxnews" ["mvn-assetUUID"]=> string(13) "1228085488001" ["mvn-mavenId"]=> array(0) { } ["mvn-creationDate"]=> string(25) "2011-10-20T08:38:49-04:00" ["mvn-airDate"]=> string(25) "2011-10-20T08:38:49-04:00" ["mvn-shortDescription"]=> string(20) "Bob Massi sounds off" ["mvn-mitvAudioOnly"]=> string(5) "false" ["mvn-fnc_mp3"]=> array(0) { } ["mvn-fnc_grab_50x50"]=> string(68) "http://video.foxnews.com/thumbnails/102011/50/50/ff_massi_102011.jpg" ["mvn-fnc_grab_103x58"]=> string(69) "http://video.foxnews.com/thumbnails/102011/103/58/ff_massi_102011.jpg" ["mvn-fnc_grab_156x88"]=> string(69) "http://video.foxnews.com/thumbnails/102011/156/88/ff_massi_102011.jpg" ["mvn-flv1200"]=> string(60) "http://media2.foxnews.com/102011/ff_massi_102011_FNC_MED.mp4" ["mvn-fnc_framework"]=> array(0) { } ["mvn-fnc_channel"]=> string(6) "on_air" ["mvn-domain"]=> array(0) { } ["mvn-duration"]=> string(3) "188" ["mvn-fnc_feedTag"]=> array(0) { } ["mvn-fnc_format"]=> string(2) "NA" ["mvn-fnc_category"]=> string(35) "on_air|fox_friends|shattered_dreams" ["mvn-fnc_category2"]=> string(26) "personality|brian_kilmeade" ["mvn-fnc_show"]=> string(2) "NA" ["mvn-fnc_default_playlist"]=> array(0) { } ["mvn-fnc_personality"]=> string(2) "NA" ["mvn-fnc_mp4"]=> string(61) "http://media2.foxnews.com/102011/ff_massi_102011_FNC_HIGH.mp4" ["mvn-fnc_grab_320x240"]=> string(70) "http://video.foxnews.com/thumbnails/102011/320/240/ff_massi_102011.jpg" ["mvn-fnc_grab_90x70"]=> string(68) "http://video.foxnews.com/thumbnails/102011/90/70/ff_massi_102011.jpg" ["mvn-source"]=> string(8) "Fox News" } } } }
When I do this:
$contents = file_get_contents("http://video.foxnews.com/v/feed/video/1228085488001.js");
var_dump(json_decode($contents->contents->channel->item->title, true));
It outputs:
NULL
What can I do to just get these variables from the .js file:
contents->channel->item->**title**
contents->channel->item->media-content->**media-description**
contents->channel->item->media-content->**mvn-fnc_grab_103x58**
Upvotes: 0
Views: 5776
Reputation: 2389
By specifying true
as the last parameter to json_decode
, you're telling it to decode into an associative array. If you want to access the elements using object notation, don't use true
as the last parameter:
$contents = file_get_contents("http://video.foxnews.com/v/feed/video/1228085488001.js");
var_dump(json_decode($contents));
Upvotes: 3