Results 1 to 10 of 10

Thread: Daily Content in PHP

  1. #1
    Join Date
    May 2008
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Daily Content in PHP

    Script: Daily iframe content II
    http://www.dynamicdrive.com/dynamici...dowiframe2.htm

    I know there are javascript ones available, which allow for the Daily iframe content to be modified into weekly and monthly (thanks very much to those already posted in this forum about those!) I just wanted to inquire if it is possible for this to be also done in PHP? I've searched around the web and found some clues, but I'm pretty new at PHP and unfamiliar with all of the attributes. In a nutshell, I'm looking for a PHP script that will automatically "update" (change the page) weekly and/or monthly. Thank you!

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    If you're using the same setup as the script you linked to, you can use something like this:

    Weeks:
    PHP Code:
    <?php
       
    echo date('W').".html";  // output 21.html
    ?>
    Months:
    PHP Code:
    <?php
       
    echo date('n').".html";  // ouput 5.html
    ?>
    You could add these into the src= parameter of your iframe tag and won't need any javascript there.
    Last edited by Medyman; 05-22-2008 at 08:03 PM.

  3. The Following User Says Thank You to Medyman For This Useful Post:

    Feldt (05-22-2008)

  4. #3
    Join Date
    May 2008
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the echo tip! I was just wondering if it's possible to take a step further where it's just a array/switch function? For example I found the below, which changes daily (I don't know if there are any errors with the coding, it's just a tutorial code for a daily change...I wanted to have a weekly/monthly change without it having the header( and changing it to echo):

    <?php $b = time () ;
    $day = date("D",$b) ;

    //Here we redirect the user to a differnt programming site based on what day of the week it is.

    switch($day){
    case "Sun": header( 'Location: http://php.about.com' ) ;
    case "Mon": header( 'Location: http://webdesign.about.com' ) ;
    case "Tue": header( 'Location: http://javascript.about.com' ) ;
    case "Wed": header( 'Location: http://perl.about.com' ) ;
    case "Thu": header( 'Location: http://python.about.com' ) ;
    case "Fri": header( 'Location: http://ruby.about.com' ) ;
    case "Sat": header( 'Location: http://cplus.about.com' ) ;
    }

    ?>

  5. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Oh, I see...

    Using the same logic, you would just substitute date("W") for date("D",$b) in the above code. Then in your case statements, the values would be the week number (1 through 52).

    Similarly, you could use date("n") for months. This outputs the month number (1 through 12). Or you could use date("M") which outputs abbreviations for months (Jan, Feb, Mar etc...). date("F") outputs full months names (January, February, etc...).

    Does that help?

  6. #5
    Join Date
    May 2008
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    I actually did try both those options before posting in this forum ^^ unfortunately, I wasn't sure if I wrote anything wrong or it was the script itself. However, since you also indicated to just do the the above, it seems like that script doesn't work. It only shows the last URL i.e. "December"...doesn't show "May."

    I guess I'll fiddle around some more, thanks for help.

  7. #6
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Hmm, sorry... I didn't even really think about testing the script that you posted.

    Try this:

    PHP Code:
    <?php
    $month 
    date("F") ;

    switch(
    $month){
    case 
    "January": echo "January"; break;
    case 
    "February": echo "February"; break;
    case 
    "March": echo "March"; break;
    case 
    "April": echo "April"; break;
    case 
    "May": echo "May"; break;
    case 
    "June": echo "June"; break;
    case 
    "July": echo "July"; break;
    case 
    "August": echo "August"; break;
    case 
    "September": echo "September"; break;
    case 
    "October": echo "October"; break;
    case 
    "November": echo "November"; break;
    case 
    "December": echo "December"; break;
    }

    ?>
    This just prints the month instead of forwards you to a website, but you should get the concept. The break; was missing from the script you posted.

  8. The Following User Says Thank You to Medyman For This Useful Post:

    Feldt (05-23-2008)

  9. #7
    Join Date
    May 2008
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Yay! Thanks so much! It works perfectly =) And yes I figured out how to make it show up with URLs and etc. Cheers.

  10. #8
    Join Date
    May 2008
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Two last questions >< by using this script would it update via my server time? Or some other mean time i.e. UTC/GMT and is it possible to edit to so it updates via whatever - or + GMT I choose?

    Would it be using a code...I know that's new only to PHP5.1?
    date_default_timezone_set('-8GMT');

  11. #9
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Two last questions >< by using this script would it update via my server time? Or some other mean time i.e. UTC/GMT and is it possible to edit to so it updates via whatever - or + GMT I choose?
    date() pulls your server time. gmdate() pulls GMT. So use whichever you want to use.

    Check the usernotes on the gmdate page in the PHP docs for some ways to convert between time zones.

    Yes, it will require some code. If you have PHP 5.1+ on your server, you can use date_default_timezone_set(), if you'd like.

  12. #10
    Join Date
    Jun 2008
    Location
    Parkersburg, WV
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Is it possible to use this script with an XML file so no real server intervention is required. (I'm being hosted by Yahoo! and PHP is been nothing but headaches.)

Bookmarks

Posting Permissions

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