Skip to content Skip to sidebar Skip to footer

Take Broadcast Program

I have a channel publishing sites and I wanna get into the channel CNN broadcast program.. CNN broadcast the program here: (you can see in source) http://edition.cnn.com//CNNI/sche

Solution 1:

Yes, it's possible:

<?php

$html = file_get_contents('http://edition.cnn.com//CNNI/schedules/json/CSI.EU.html');

preg_match('#<textarea id="jsCode">(.*)</textarea>#is', $html, $matches);

$json = trim($matches[1]);
$json = str_replace("'", '"', $json);
$json = preg_replace('#([\w]+): ("|\[)#is', '"\\1": \\2', $json);

$json = json_decode($json, TRUE);

$startTimeUnix = time();
foreach($json['airings'] as $key => $value)
{
  if ($value['startTimeUnix'] > $startTimeUnix)
    break;
}

echo 'Now: ' , $json['airings'][$key]['programName'];   # CNN Newsroom
echo 'Next: ', $json['airings'][++$key]['programName']; # World Sport

Post a Comment for "Take Broadcast Program"