Im not very good with PHP but I decided to try and create a small script that receives a JSON file from a url. I want to split up this data into a simple TV schedule for the current day. I just cant figure out how to select the info I require from the array. Heres my current code, like I said my PHP knowledge is limited, but the task isnt actually that difficult, or so I thought.
The script should output something like
Showname - Season Number - Episode Number - Airtime
I havnt added all the pieces I need to my code yet,, but I cant even get the Episode and Season data. Any help would be massively appreciated.
The commented part at the bottom if uncommented will just print the $data array so you can see the structure of it.Code:<?php $today = date("Y-m-d"); $url = "http://api.tvmaze.com/schedule?date=" . $today; $json = file_get_contents($url); $data = json_decode($json,true); $last = count($data) - 1; // might need later foreach ($data as $kkey => $item ) { $season = $kkey['season']; $ep = $kkey['number']; foreach ($kkey['show'] as $key => $value) { $showname = $key['name']; print "Schedule For " . $today . "\r\n"; print $showname . " - " . $season . " - " . $ep . "\r\n"; } } //print"<pre>"; //print_r($data); //print "</pre>"; ?>
Social Networking Bookmarks