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
New to PHP, have specific question...
Moderator: General Moderators
-
analog.kid
- Forum Newbie
- Posts: 3
- Joined: Thu Oct 23, 2003 6:41 pm
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.
?>-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
why is there a include function is require is so much better?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. ?>
-
analog.kid
- Forum Newbie
- Posts: 3
- Joined: Thu Oct 23, 2003 6:41 pm
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:
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 ?
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>';
?>Hope this helps ?
-
analog.kid
- Forum Newbie
- Posts: 3
- Joined: Thu Oct 23, 2003 6:41 pm
You can use strtolower() to change "Fri" to "fri"
http://us4.php.net/manual/en/function.strtolower.php
http://us4.php.net/manual/en/function.strtolower.php