| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| DomainersUniversity.com Team Leader | Need a special PHP 'include' Let's say I have hundreds of HTML files, each named for a particular day of the year. I need to use the PHP 'include' code so on any particular system date, the matching HTML file is included. So, since today is August 27, 2008, the 'include' file should be 2008-08-27.html Understand that the html files have not been created yet, so the naming of these files can be in a different date format if need be. ------------------------ Then I need to have another 'include' code that will take the system date and subtract a number of days, so it will 'include' a HTML file that is X number of days in the past. For example, today is August 27, 2008, and I want the web page to 'include' a file named for a date 3 days ago, which would be 2008-08-24.html. ------------------------ Seems like a fairly simple thing to do, but I don't know coding well enough to figure it out. Any help would be great! . |
| |
| | #2 (permalink) |
| No Country for Old Domainers ... Member Services | Well the part of it to include "Today" could be : Code:
<?php
$today = date("Ymd");
include("includes/$today.php");
?>
Code: $yesterday = $today-1; That may be a bit too simple for what you are looking for Gene - But it's 8 AM here and I'm out of Mountain Dew ![]() SOS DEW ME ! Obviously - That is limited to one month though ... |
| |
| | #3 (permalink) |
| DomainersUniversity.com Team Leader | Thanks Mark! That seems like it would work (based on my limited understanding of PHP), but I'm wondering why you say it would be limited to 1 month. Couldn't it say $yesterday = $today-47; for instance? So do I have this right? PHP Code: ---------------------------- EDIT: Mark, you're da man! I just tried the code and it works perfectly. THANK YOU! . Last edited by Gene; 08-27-2008 at 06:24 AM. |
| |
| | #4 (permalink) | |
| No Country for Old Domainers ... Member Services | No - it wont work for other months due to the fact it is combining Y M D into one number. "20080827" is just "20 Million 80 thousand and 27" to the script. If you subtract more than 26 , There would be an error if you tried to incude any pages. For individual dates , You really need a more detailed Calendar set up and something in the script to ask "if file exists" to make sure it doesn't try to include dates non-existent. http://www.php.net/date has all of the available formats. I'm thinking in your case maybe using the "Day of Year" format may help. Quote:
Code: $today = date("Ymd");
if(!isset($filename) || !$filename || $filename == ""){$filename = "database/$today.txt";}
if(!file_exists("$filename")) {
///it does exist - so retrieve and show data (include it in your case)
} else {
///it doesn't exist - So no Go (I actually create the database here on my script)
}
I'd bet some of these younger "whippersnappers" might have a better way to do this than me | |
| |
| | #6 (permalink) |
| Traveller | The strtotime function is almost unbelievably clever at working out date stuff, you can even tell it what to do in almost plain english: Code: $yesterday = date('Ymd', strtotime("-1 day"));
$lastmonth = date('Ymd', strtotime("-1 month"));
Code: strtotime("last Monday")
strtotime("next Thursday")
__________________ Internet.geek.nz NameCooler.com Unlimited Domain Name Web Hosting Travel Money Rates |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |