Log in

View Full Version : Daily Content in PHP



Feldt
05-22-2008, 03:45 PM
Script: Daily iframe content II
http://www.dynamicdrive.com/dynamicindex17/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!

Medyman
05-22-2008, 06:21 PM
If you're using the same setup as the script you linked to, you can use something like this:

Weeks:

<?php
echo date('W').".html"; // output 21.html
?>

Months:

<?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.

Feldt
05-22-2008, 06:59 PM
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' ) ;
}

?>

Medyman
05-22-2008, 08:01 PM
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?

Feldt
05-23-2008, 12:06 AM
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.

Medyman
05-23-2008, 01:18 AM
Hmm, sorry... I didn't even really think about testing the script that you posted.

Try this:


<?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.

Feldt
05-23-2008, 02:28 AM
Yay! Thanks so much! It works perfectly =) And yes I figured out how to make it show up with URLs and etc. Cheers.

Feldt
05-23-2008, 03:23 PM
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');

Medyman
05-23-2008, 05:56 PM
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 (http://us2.php.net/gmdate) 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.

gemcgraw
06-19-2008, 09:43 PM
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.)