Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Script Help

  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Script Help

    Hi, I am looking to create a script in PHP that automatically changes text once a month so for example in December I want a certain bit of text to show and in January Another. Hope that makes sense

    Thanks in advance
    Danny

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    Try this.

    PHP Code:
    <?php
    $month
    =date(m);
    $text=array("01"=>"January","02"=>"February","03"=>"March","04"=>"April","05"=>"May","06"=>"June","07"=>"July","08"=>"August","09"=>"September","10"=>"October","11"=>"November","12"=>"December");
    echo 
    $text[$month];
    ?>
    If you can't stand behind your troops, feel free to stand in front of them
    Semper Fidelis

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The only thing I'd change from the above is I'd use n instead of m (btw you'll have an undefined constant from the m in there jh).
    PHP Code:
    <?php
    $text 
    = array(
        
    => 'Text for january',
        
    => 'Text for february',
        
    //....
    );

    print 
    $text[date('n')];
    ?>

  • #4
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    Ooops missed that. Thanks
    If you can't stand behind your troops, feel free to stand in front of them
    Semper Fidelis

  • #5
    New Coder
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you for the replys but dont think I described it to well, what I need is something that in july will say for example its hot and in december for example say its cold and have these automatically change at the beginning of every month

  • #6
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    What Fou-Lu posted will do exactly that. Whatever text you put in the array for each month will be displayed for that month and change on the first of every month.
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •