我正在決議 XML 鏈接。我現在得到了廣播的標題,但我無法得到下一個廣播的標題。如果有人可以幫助我,我將不勝感激
<?php
$url = 'https://hls.airy.tv/airytv/33';
$xml=simplexml_load_file("$url");
$line = 0;
$time = date( "YmdHi" );
foreach($xml->xpath('programme[@channel="33"]') as $item) {
$start = substr( (string)$item["start"], 0, -8);
$end = substr( (string)$item["stop"], 0, -8);
if ($time > $start && $time < $end) {
echo "Now : ".$item->title. "<br>";
echo "Next : ".$item->title.[$line 1];
}
$line ;
}
?>
輸出
Now : Let's_Go_Thailand_Koh_Lanta;_a_place_the_discover_Ep_021
Next : Let's_Go_Thailand_Koh_Lanta;_a_place_the_discover_Ep_021Array
XML
<programme start="20220623090024 0000" stop="20220623093300 0000" channel="33">
<title lang="en">Let's_Go_Thailand_Koh_Lanta;_a_place_the_discover_Ep_021</title>
<sub-title lang="en">Let's_Go_Thailand_Koh_Lanta;_a_place_the_discover_Ep_021</sub-title>
<desc lang="en"/>
<date>20220623</date>
<publisher/>
<category lang="en">Featured</category>
<category lang="en">Airy TV 1</category>
</programme>
<programme start="20220623093300 0000" stop="20220623100301 0000" channel="33">
<title lang="en">Let's_Go_Thailand_Moment_by_Moment_Harvest_Ep_023</title>
<sub-title lang="en">Let's_Go_Thailand_Moment_by_Moment_Harvest_Ep_023</sub-title>
<desc lang="en"/>
<date>20220623</date>
<publisher/>
<category lang="en">Featured</category>
<category lang="en">Airy TV 1</category>
</programme>
uj5u.com熱心網友回復:
試試這個,它對我有用:
<?php
$url = 'https://hls.airy.tv/airytv/33';
$xml=simplexml_load_file("$url");
$time = date( "YmdHi" );
$currTitle = null;
$nextTitle = 'N/A';
foreach($xml->xpath('programme[@channel="33"]') as $item)
{
if ($currTitle != null)
{
$nextTitle = $item->title;
break;
}
$start = substr( (string)$item["start"], 0, -8);
$end = substr( (string)$item["stop"], 0, -8);
if ($time > $start && $time < $end)
{
$currTitle = $item->title;
}
}
echo "Now : $currTitle<br />Next : $nextTitle";
?>
我認為您不能像嘗試使用 foreach 那樣進行前瞻,因此您可以在找到具有適當時間的記錄時保存標題,并讓回圈再進行一次選擇上一個記錄。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/495846.html
