Answer the question
In order to leave comments, you need to log in
How to display additional fields from XML?
I sketched a script, the script works fine, but you need to display more fields 2 fields are the following.
There is an XML TV program file for a week, it displays only one line on a specific channel, but you need to display what will be next 2 ~ 3 programs, what will go on.
XML-TV looks like this.
<programme start="20160312041000" stop="20160312042000" channel="2">
<title lang="ru">Местное время. Вести-Москва</title>
<desc lang="ru">Произведено: Россия. Самая свежая и объективная информация обо всех гранях жизни столицы и области.</desc>
<category lang="ru">Новости</category>
<credits>
<director>Екатерина Григорова</director>
<actor>Екатерина Коновалова</actor>
<actor>Олег Тонконог</actor>
<actor>Алексей Фролов</actor>
</credits>
</programme>
<programme start="20160312042000" stop="20160312061500" channel="2">
<title lang="ru">Когда цветет сирень</title>
<desc lang="ru">Произведено: Россия. Главная героиня живёт в маленькой квартире со своей пожилой матерью и маленьким сыном. Чтобы содержать семью, она вынуждена много работать и времени на личную жизнь у неё практически не остаётся. Подруга, работающая домработницей в богатой семье, чтобы хоть немного развлечь героиню, зовёт её с собой в гости к друзьям своего жениха...</desc>
<category lang="ru">Фильм</category>
<credits>
<director>Сергей Борчуков</director>
<actor>Людмила Курепова</actor>
<actor>Елена Захарова</actor>
<actor>Антон Макарский</actor>
<actor>Александр Пороховщиков и другие</actor>
</credits>
<date>2010</date>
</programme>
$G = date ("G") - 1;
$date = date("Ymd".$G."is");
$channel = 3;
$tv = new SimpleXMLElement ("xmltv.xml", 0, true);
foreach ($tv as $v)
{
if ($date >= $v->attributes()->start && $date <= $v->attributes()->stop )
{
if ($v->attributes()->channel == $channel)
{
echo "<h2>".$v->title." (".$v->category.")</h2>";
echo "<h3>".$v->desc."</h3><br />";
}
}
}
Answer the question
In order to leave comments, you need to log in
$found = false;
foreach ($tv as $i => $v)
{
if (!$found && ($date >= $v->attributes()->start && $date <= $v->attributes()->stop ))
{
if ($v->attributes()->channel == $channel)
{
echo "<h2>".$v->title." (".$v->category.")</h2>";
echo "<h3>".$v->desc."</h3><br />";
$found = $i;
}
} elseif($i - $found <= 2) {
if ($v->attributes()->channel == $channel)
{
echo "<h2>".$v->title." (".$v->category.")</h2>";
echo "<h3>".$v->desc."</h3><br />";
}
} else {
break;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question