sotusotusotu Posted March 27, 2008 Share Posted March 27, 2008 Hi guys, I have 2 swf files and I want them to alternate on a Monday morning every week. I don't need to retrive the files from a database or a file or anything like that. Does any know the best way of doing this or have done this before? Cheers in advance. Quote Link to comment https://forums.phpfreaks.com/topic/98152-weekly-rotating/ Share on other sites More sharing options...
laffin Posted March 27, 2008 Share Posted March 27, 2008 maybe using sumfin like $which=(intval(date("W")))&1; it takes the week number (52 weeks in a year), and strips off all higher numbers besides 1. so giving u 2 states 0 or 1. Quote Link to comment https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502129 Share on other sites More sharing options...
sotusotusotu Posted March 27, 2008 Author Share Posted March 27, 2008 Thanks a lot Laffin. If the number is "1" now then obviously(hopefully) next week it will be "0". Do you know the exact point it will change? Is it Monday at 00:01 am? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502141 Share on other sites More sharing options...
moon 111 Posted March 27, 2008 Share Posted March 27, 2008 There is probably a much better way of doing this but here is my code: <?php $txtfile = 'file.txt'; $file1 = "file1.swf"; $file2 = "file2.swf"; $handle = fopen($txtfile, 'rw'); if(filesize($txtfile) > 0) $contents = fread($handle, filesize($txtfile)); else $contents = ""; if(!empty($contents)) { $date = explode(',', $contents); if(date('D') == "Mon") { if($date[0] != date('d')) { if($date[1] == $file1) $file = $file2; else $file = $file1; fwrite($handle, date('d') . ',' . $file); } } } else { $file = $file1; fwrite($handle, date('d') . ',' . $file); } echo $file; // Display the swf's name. Change this to whatever. ?> You need an empty file 'file.txt' (you can change the name in the code). Quote Link to comment https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502145 Share on other sites More sharing options...
laffin Posted March 27, 2008 Share Posted March 27, 2008 Thanks a lot Laffin. If the number is "1" now then obviously(hopefully) next week it will be "0". Do you know the exact point it will change? Is it Monday at 00:01 am? Cheers Correct According to php doc on date function ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) So it shud start at 00:01 am Monday Quote Link to comment https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502150 Share on other sites More sharing options...
sotusotusotu Posted March 27, 2008 Author Share Posted March 27, 2008 There is probably a much better way of doing this but here is my code: <?php $txtfile = 'file.txt'; $file1 = "file1.swf"; $file2 = "file2.swf"; $handle = fopen($txtfile, 'rw'); if(filesize($txtfile) > 0) $contents = fread($handle, filesize($txtfile)); else $contents = ""; if(!empty($contents)) { $date = explode(',', $contents); if(date('D') == "Mon") { if($date[0] != date('d')) { if($date[1] == $file1) $file = $file2; else $file = $file1; fwrite($handle, date('d') . ',' . $file); } } } else { $file = $file1; fwrite($handle, date('d') . ',' . $file); } echo $file; // Display the swf's name. Change this to whatever. ?> You need an empty file 'file.txt' (you can change the name in the code). Thanks a lot for this example. I think this is actually more detailed than I need but will keep the example as I am sure it will get more complicated in future. Quote Link to comment https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502160 Share on other sites More sharing options...
sotusotusotu Posted March 27, 2008 Author Share Posted March 27, 2008 Thanks a lot Laffin. If the number is "1" now then obviously(hopefully) next week it will be "0". Do you know the exact point it will change? Is it Monday at 00:01 am? Cheers Correct According to php doc on date function ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) So it shud start at 00:01 am Monday Thanks a lot mate. Quote Link to comment https://forums.phpfreaks.com/topic/98152-weekly-rotating/#findComment-502162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.