| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| DomainersUniversity.com Join Date: Feb 2005 Location: Oswego, NY
Posts: 4,735
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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! .
__________________ . . Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com ----------------------------------------------------------------------------------------------- |
| |
| | #2 (permalink) |
| Hi :) Join Date: Mar 2004 Location: NC
Posts: 9,566
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Well the part of it to include "Today" could be : Code:
<?php
$today = date("Ymd");
include("includes/$today.php");
?> ????: NamePros.com http://www.namepros.com/programming/508057-need-a-special-php-include.html 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 ... |
| |
| | THREAD STARTER #3 (permalink) |
| DomainersUniversity.com Join Date: Feb 2005 Location: Oswego, NY
Posts: 4,735
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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! .
__________________ . . Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com -----------------------------------------------------------------------------------------------
Last edited by Gene; 08-27-2008 at 07:24 AM.
|
| |
| | #4 (permalink) | ||||
| Hi :) Join Date: Mar 2004 Location: NC
Posts: 9,566
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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.
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 | ||||
| |
| | THREAD STARTER #5 (permalink) |
| DomainersUniversity.com Join Date: Feb 2005 Location: Oswego, NY
Posts: 4,735
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | You're right... I just tried doing a -30 and it failed... it won't overlap into the previous month. Thanks for the additional info though!
__________________ . . Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com ----------------------------------------------------------------------------------------------- |
| |
| | #6 (permalink) |
| Traveller Join Date: Mar 2007 Location: Yet another city
Posts: 1,419
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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")); ????: NamePros.com http://www.namepros.com/showthread.php?t=508057 Code: strtotime("last Monday")
strtotime("next Thursday")
__________________ NameCooler.com |
| |
| | THREAD STARTER #7 (permalink) |
| DomainersUniversity.com Join Date: Feb 2005 Location: Oswego, NY
Posts: 4,735
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | -NC-! Beautiful! That works like a charm... man you've saved me a lot of hair-pulling. Thanks so much.
__________________ . . Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com ----------------------------------------------------------------------------------------------- |
| |
| | THREAD STARTER #9 (permalink) |
| DomainersUniversity.com Join Date: Feb 2005 Location: Oswego, NY
Posts: 4,735
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Thanks to both of you for taking the time! And Mark, you're still the best eye-poker
__________________ . . Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com ----------------------------------------------------------------------------------------------- |
| |