Page 1 of 1

New to PHP, have specific question...

Posted: Thu Oct 23, 2003 6:41 pm
by analog.kid
Hi, I'm brand new to PHP. Here is my question:

I'm working on a website that wants to include a page in a box on the front page. The catch is, there are 14 pages to include, 2 for ever day of the week. What I need is a way to identify what day and time it is when the user accesses the page, and then include the correct page in the box for them to view.

I've been looking at getdate and related things, and I know more or less how to do includes, but I have no idea how to tie them together so this will work.

Can anyone point me in the right direction? TIA

a.k

Posted: Thu Oct 23, 2003 7:28 pm
by Gen-ik
Rename those 14 files that you need to include to things like mon_am.htm, mon_pm.htm, tue_am.htm, wed_am.htm, sat_pm..... etc..... and then this code should work.

Code: Select all

<?

$getfile = date("D_a")."htm"; // that will give you the file name to include.. ie sun_am.htm

require($getfile); // same as include() but will tell you if any errors pop up.

?>

Posted: Thu Oct 23, 2003 8:29 pm
by d3ad1ysp0rk
Gen-ik wrote:Rename those 14 files that you need to include to things like mon_am.htm, mon_pm.htm, tue_am.htm, wed_am.htm, sat_pm..... etc..... and then this code should work.

Code: Select all

<?

$getfile = date("D_a")."htm"; // that will give you the file name to include.. ie sun_am.htm

require($getfile); // same as include() but will tell you if any errors pop up.

?>
why is there a include function is require is so much better?

Posted: Thu Oct 23, 2003 8:48 pm
by analog.kid
Gen-ik, thank you for your help! I'll try it out once I figure out why I can't upload to my site :roll:

a.k

Posted: Thu Oct 23, 2003 8:56 pm
by nigma
When did he say require() is better than include() ??

The difference between require() and include() is that require() will cause a fatal error if the file cannot be included, include() produces an error.

So, if you have the following code:

Code: Select all

<?php
require("topOfPage.html");
echo '<p>main stuff</p>';

?>
Now, if topOfPage.html doesn't exist, or it cannot be included then nothing but an error will be produced on the page, you will not see "main stuff." If you use include() instead of require() you will also see an error, but in addition to the error you will see the text "main stuff."

Hope this helps ?

Posted: Fri Oct 24, 2003 10:22 pm
by analog.kid
Thanks again, Gen-ik - that code seems to be the answer. I did have to change "htm" to ".htm" to make it work, though. Also my files had to be renamed with capitalized days ("Fri" instead of "fri") but other than that, it works like a charm.

:D

a.k

Posted: Mon Oct 27, 2003 7:25 pm
by nigma
You can use strtolower() to change "Fri" to "fri"
http://us4.php.net/manual/en/function.strtolower.php