用于实时广播时间表的 PHP 文件


PHP file for live radio schedule

我并不像我想象的那样精通PHP,并且正在努力解决我希望非常简单的事情。

基本上,对于广播电台网站,脚本从Google Doc(电子表格)中读取,并在用户访问网站时显示节目,以及接下来的内容。

我正在尝试在列表中额外包含下一个节目(所以播出节目,下一个节目和之后的节目)。

但是我完全陷入困境并不断导致解析错误。

如果有任何帮助,将不胜感激!

谢谢

马丁

<?php 
// Now On Air and who's on next ...
// Default city Time
$default="Europe/London";
date_default_timezone_set($default);
$days=array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
// What time is it right now
$now=time();
$year=date("Y");
$month=date("m");
$day=date("d");
$dow=strtoupper(date("D"));
// https://docs.google.com/spreadsheet/xxxx
$schedule ="http://spreadsheets.google.com/feeds/cells/xxxx";
// Get the Google Docs Spreadsheet
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL,"$schedule"); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); 
$pres = curl_exec($curl); 
curl_close($curl); 
$xml_pres = simplexml_load_string($pres); 
// Build an array of the schedule
$build=array();
foreach ($xml_pres->entry as $item) {
$col=ord(substr($item->title,0,1))-65;
$row=substr($item->title,1);
$build[$row][$col]=$item->content;
}
$rend=$row;
// how many lines in the array ...
$count=count($build);
// 0=day
// 1=start time
// 2=end time
// 3=show name
// 4=description
// 5=presenter
// 6=photo
// 7=link
// 
// Example: $build[$i][4] is the description of line number $i
// Find out who is on the air right now
$flag=0;
for($i=2;$i<=$rend;$i++){
// day of week conversion
if(strtoupper($build[$i][0])=="SUNDAY"){
$dw="SUN";
}
if(strtoupper($build[$i][0])=="MONDAY"){
$dw="MON";
}
if(strtoupper($build[$i][0])=="TUESDAY"){
$dw="TUE";
}
if(strtoupper($build[$i][0])=="WEDNESDAY"){
$dw="WED";
}
if(strtoupper($build[$i][0])=="THURSDAY"){
$dw="THU";
}
if(strtoupper($build[$i][0])=="FRIDAY"){
$dw="FRI";
}
if(strtoupper($build[$i][0])=="SATURDAY"){
$dw="SAT";
}
   if($dow==$dw && $flag==0){
        $start_time=strtotime($year."-".$month."-".$day." ".$build[$i][1]);
           if($build[$i][1]=="00:00:00"){
           $startt="00:00am";
           }
           else{
           $startt=date("g:00a", $start_time+($timeadjust*60*60));
           }
        $stop=$build[$i][2];
        if($stop=="0:00:00" || $stop=="00:00:00"){
        $stop="23:59:00";
        }
        $stop_time=strtotime($year."-".$month."-".$day." ".$stop);
              if($stop=="23:59:00"){
              $stopt="Midnight";
              }
              else{
              $stopt=date("g:00a", $stop_time+($timeadjust*60*60));
              }
            if($now >= $start_time && $now < $stop_time){
            $photo="/nophoto.jpg";
            if($build[$i][6]){
            $photo=$build[$i][6];
         
		 }
		
         
            echo"
           <img src='$photo' alt='{$build[$i][5]}' title='{$build[$i][5]}' style='float:left'><br><span id='onairtext'>On Air Now:</span><br><span id='djname'><a href='{$build[$i][7]}'>{$build[$i][3]}</a></span><br><span id='showtime'>$startt - $stopt</span><br><img src='/djspacer.jpg' border='0'><br>
            ";
            $next=$i+1;
               if($next > $rend){
                $next=2;
                }
$np=0;
for($q=$next; $q<=$rend; $q++){
    $no=strtolower($build[$q][3]);
    if($no=="no programming" || $np==1){
    // nothing
    }
    else{
    $next=$q;
    $np=1;
    
$flag=0;
$year="2011";
$month="11";
$day="20";
if(strtoupper($build[$next][0])=="SUNDAY"){$day="20";}
if(strtoupper($build[$next][0])=="MONDAY"){$day="21";}
if(strtoupper($build[$next][0])=="TUESDAY"){$day="22";}
if(strtoupper($build[$next][0])=="WEDNESDAY"){$day="23";}
if(strtoupper($build[$next][0])=="THURSDAY"){$day="24";}
if(strtoupper($build[$next][0])=="FRIDAY"){$day="25";}
if(strtoupper($build[$next][0])=="SATURDAY"){$day="26";}
$start_time=strtotime($year."-".$month."-".$day." ".$build[$next][1]);
$startt=date("g:00a", $start_time+($timeadjust*60*60));
        $photox="/nophoto.jpg";
            if($build[$next][6]){
            $photox=$build[$next][6];
        }     
            echo"
            <img src='$photox' alt='{$build[$next][5]}' title='{$build[$next][5]}' style='float:left'><span id='showtime'><b>Next:</b>&nbsp;$startt<br><a href='{$build[$next][7]}'>{$build[$next][3]}</a></span>
	
            ";
            $flag=1;    
    }
}
            
        }    
    }
}
?>

设法通过

复制来解决这个问题:

$next=$i+1; if($next > $rend){ $next=2;

通过添加另一个唯一名称并为第一行添加 +2。

此外,复制日期时会使用此新名称以及每次照片的唯一名称构建。现在显示 3 即将上映的节目。完善。