Reputation: 5
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 - XML file):
http://tvprofil.net/xmltv/data/cnn.info/weekly_cnn.info_tvprofil.net.xml
How the data according to the time of withdrawal?
For example:
Now program: "bitmez's table"
next program: "stack's table" in 30 minute
Is this possible?
Update 1:
I can take the XML data but to all of XML file-
<?php
$url = 'http://tvprofil.net/xmltv/data/cnn.info/weekly_cnn.info_tvprofil.net.xml';
$xml = simplexml_load_file($url);
if (!$xml) {
trigger_error('XML file -- read error',E_USER_ERROR);
return;
}
foreach ($xml as $programme) {
echo 'Now: ', $programme->title, "<br>\n";
}
Upvotes: 0
Views: 1778
Reputation: 19380
<?php
$url = 'weekly_cnn.info_tvprofil.net.xml';
$xml = simplexml_load_file($url);
$now = new DateTime('now');
$it = new IteratorIterator($xml->programme);
foreach ($it as $programm)
{
$start = DateTime::createFromFormat('YmdHis', $programm['start']);
if ($start > $now)
break;
}
echo 'Now: ', $programme->title;
$it->next();
if ($it->valid) {
echo 'Next: ', $it->current()->title;
}
off-topic Please, don't email me with requests, just because I answered your question, doesn't mean I need to do it again. It's basically the same, learn by using manual, for your own sake. Cheeers.
Upvotes: 2
Reputation: 166
You need to get the attributes and compare them
$url = 'http://tvprofil.net/xmltv/data/cnn.info/weekly_cnn.info_tvprofil.net.xml';
$array = (array) simplexml_load_file($url);
// FLATTEN THE RESULT SET
$programmes = array();
foreach ($array as $k => $v)
{
if ($k == 'programme'){
foreach($v as $p)
{
$programmes[] = (array) $p;
}
break;
}
}
$tim = time();
$now = array();
$nex = array();
foreach ($programmes as $show)
{
$attr = $show['@attributes'];
if ($tim >= $attr['start'] && $tim <= $attr['stop'])
{
// GETS THE CURRENT SHOW
$now = $show;
}
}
print_r($now);
Upvotes: -1