- Code: Select all
<?PHP
$dir='/path/to/xml/';
$defaultfile = '/location/of/default/file.xml';
$curdate = date("Ymd");
$curtime = date("Gi");
$files = scandir($dir);
foreach ($files as $file)
{
if ($file!='.' && $file!='..')
{
$array = explode("_",$file);
$pname = $array[0];
$dstart = $array[1];
$tstart = $array[2];
$dstop = $array[3];
$tstop = $array[4];
$tstop = rtrim($tstop, '.xml');
if (($curdate >= $dstart)
&& ($curdate <= $dstop)
&& ($curtime >= $tstart)
&& ($curtime <= $tstop))
{
echo file_get_contents("$dir$file");
break;
}
else
{
echo file_get_contents("$defaultfile");
break;
}
}
}
?>
The files located in the $dir path are as follows: morning_20110620_0800_20110625_1200.xml & afternoon_20110620_1201_20110625_1800.xml. I am trying to get the above code to break apart each file into its corresponding array element. Then its to compare the start and stop date and time - based on $curdate and $curtime. It works when I don't have a 'else echo...$defaultfile' line in there. I am trying to get it so after the 25th of June, it reverts back to the default playlist. Can anyone see where I have mis-coded? Thank you for reading!


