Hi David,
Is there a way of having the this script load another feed given a certain time of day? Specifically,
We have a few radio stations that we are currently parsing the RCS feeds from and it works great. Currently, we have it reading for one station, now we have 2 stations that we are going to be streaming at different times of the day.
Station 1: 12:00am (midnight) - 2:30pm
Station 2: 2:30pm - 7:30pm
Thanks very much,
John L Wilson
Cool, sounds easy enough, but would I have to have add something to the script to have it go back to station 1 after the time of 1930 (7:30pm or 1170 minutes).
Thanks again,
John L Wilson
Hi John,
Perhaps the safest way to do it is to have station 1 as your "default" feed, and then select station 2 if the time is between 870 and 1170:
// the default feed is station1
$url = "http://www.example.com/station1.xml";
$minutes = intval(date("H")) + intval(date("i"));
// override if between 14:30 and 19:30
if (($minutes >= 870) && ($minutes <= 1170))
{
$url = "http://www.example.com/station2.xml";
}
This makes it easier to add different feeds with other times, always defaulting back to Station1 if there is nothing else selected.
Cheers,
David.
Awesome...
I will give this a try and thanks very much once again,
John L Wilson
Hi John,
Just spotted a mistake in my example - the hour value has got to be multiplied by 60 to get the correct minutes total...!
// the default feed is station1
$url = "http://www.example.com/station1.xml";
$minutes = (intval(date("H"))*60) + intval(date("i"));
// override if between 14:30 and 19:30
if (($minutes >= 870) && ($minutes <= 1170))
{
$url = "http://www.example.com/station2.xml";
}
Hello John,
Basically, you want a small block of code to decide which URL to use based on the time of day. Probably the easiest way to do this is to use minutes. The following code will give the minute of the day:
$minutes = intval(date("H")) + intval(date("i"));
Now, 2:30PM is 870 minutes; so you can combine the code above with an IF statement to decide which URL to use:
$minutes = intval(date("H")) + intval(date("i"));
if ($minutes < 870)
{
$url = "http://www.example.com/station1.xml";
}
else
{
$url = "http://www.example.com/station2.xml";
}
...you then use $url as the filename parameter in your call to MagicParser_parse().
Hope this helps!
Cheers,
David.