0

我有一个频道发布网站,我想进入频道 CNN 广播节目..

CNN在这里播放节目:(你可以在源代码中看到)

http://edition.cnn.com//CNNI/schedules/json/CSI.EU.html

数据如何按时间撤出?

例如

    Now program: "overflow's table"
    next program: "stack's table" in 30 minute  

这可能吗?

4

1 回答 1

1

是的,有可能:

<?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
于 2013-10-17T09:53:21.743 回答