1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development PHP script? What day?

Discussion in 'Software' started by JB, 20 Jan 2005.

  1. JB

    JB What's a Dremel?

    Joined:
    26 Aug 2002
    Posts:
    414
    Likes Received:
    0
    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
     
  2. Bogomip

    Bogomip ... Yo Momma

    Joined:
    15 Jun 2002
    Posts:
    5,164
    Likes Received:
    40
  3. Hwulex

    Hwulex Minimodder

    Joined:
    1 Feb 2002
    Posts:
    4,007
    Likes Received:
    1
    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. :)
     

Share This Page