Hi there, i'm looking for a php script that will read what day it is from my server (or anywhere) then depending on the day display a particular piece of code (in a php include or from a txt file or whatever. My PHP skills aren't really that hot so i wouldn't know where to start! Can anyone point me in the right direction? Thanks Jon B
you could get a timestamp using... mktime() then use date("something", $timestamp); to get the day name or whatever out of it. Then to do stuff with it, you need to use bog standard IF statements and stuff on the results see.. http://uk2.php.net/manual/en/function.date.php http://uk2.php.net/manual/en/function.mktime.php
If you're using includes to store the code you want executed, name them mon.inc, tue.inc, etc, and use this: PHP: if (!@include_once(strtolower(date('D', mktime())).'.inc')) { include_once('sun.inc'); // default if include fails } # end if Or to run code snippets in a file, this is a possibly method: PHP: switch (strtolower(date('D', mktime()))) { case 'mon': // Monday code break; case 'tue': // Tuesday code break; case 'wed': break; case 'thu': break; case 'fri': break; case 'sat': break; case 'sun': default: // Sunday (and just in case, default) code break; } # end switch Side note: this is the perfect situation for using a switch statement. Ifs for something like this are just wrong. PHP: $chrDay = strtolower(date('D', mktime())); if ($chrDay=='mon') { // do this } elseif ($chrDay=='tues') { // do this } ... etc etc. Horrible. Hope this helps.