PHP Includes and file extensions
Moderator: General Moderators
PHP Includes and file extensions
I'm new to PHP, but have the extreme basics figured out. It helps that it is similar to C++, which made it a lot easier for me to pick up on. 2 things I've ran into so far though that I need some help with.
First, my host won't parse any PHP code without having a .php extension. Is there a way around this, or should I just use the .php extension?
Second, I have a page with a link of the day, and its history. Up to now, I've been manually updating this, copy/pasting info every day. I've already been using SSI to include the link on all my pages, but I'd like to go further and automate the history...I'm in the process of switching these includes to PHP because the host won't parse .shtml files for PHP code. My question here is this...if I have file lotd111203.html and file lotd111303.html etc. how can I get PHP to automatically look for these files and include them in a loop?
First, my host won't parse any PHP code without having a .php extension. Is there a way around this, or should I just use the .php extension?
Second, I have a page with a link of the day, and its history. Up to now, I've been manually updating this, copy/pasting info every day. I've already been using SSI to include the link on all my pages, but I'd like to go further and automate the history...I'm in the process of switching these includes to PHP because the host won't parse .shtml files for PHP code. My question here is this...if I have file lotd111203.html and file lotd111303.html etc. how can I get PHP to automatically look for these files and include them in a loop?
Re: PHP Includes and file extensions
1: You have to save it as .php, else it will be processed as normal HTML, except if you use httaccess to process .html files with PHP.Cyx07 wrote:First, my host won't parse any PHP code without having a .php extension. Is there a way around this, or should I just use the .php extension?
Second, I have a page with a link of the day, and its history. Up to now, I've been manually updating this, copy/pasting info every day. I've already been using SSI to include the link on all my pages, but I'd like to go further and automate the history...I'm in the process of switching these includes to PHP because the host won't parse .shtml files for PHP code. My question here is this...if I have file lotd111203.html and file lotd111303.html etc. how can I get PHP to automatically look for these files and include them in a loop?
Re: PHP Includes and file extensions
Gotcha. Anyone else have an answer about my page includes?vigge89 wrote:1: You have to save it as .php, else it will be processed as normal HTML, except if you use httaccess to process .html files with PHP.
-
Paddy
- Forum Contributor
- Posts: 244
- Joined: Wed Jun 11, 2003 8:16 pm
- Location: Hobart, Tas, Aussie
- Contact:
Working from your example
Obviously this would only work for ten files but it will push you in the right direction hopefully.
Code: Select all
<?php
$filename = "lotd111203.html";
$filepart = "2";
while (file_exists($filename))
{
include($filename);
$filepart ++;
$filename = "lotd111".$filepart."03.html";
}
?>SWEET! I guess I just wasn't sure how to do the naming. Hopefully this worksPaddy wrote:Working from your example
Obviously this would only work for ten files but it will push you in the right direction hopefully.Code: Select all
<?php $filename = "lotd111203.html"; $filepart = "2"; while (file_exists($filename)) { include($filename); $filepart ++; $filename = "lotd111".$filepart."03.html"; } ?>
-
Paddy
- Forum Contributor
- Posts: 244
- Joined: Wed Jun 11, 2003 8:16 pm
- Location: Hobart, Tas, Aussie
- Contact:
Not sure what you mean by putting a second variable into the first. But this might help.
Will work fine.
Code: Select all
<?php
$filename = "lotd111".$filepart1.$filepart2."03.html";
?>Exactly what I was talking about. Wasn't quite sure how to say it...so that sentence after rereading it seems to be a bit of a verbal disaster. Thanks again!Paddy wrote:Not sure what you mean by putting a second variable into the first. But this might help.
Will work fine.Code: Select all
<?php $filename = "lotd111".$filepart1.$filepart2."03.html"; ?>
I could number them sequentially, but I'm using the date info for more than just the filename. Currently, the code looks like this:
The problem I'm running into (and why I'm curious about a nonexistent file) is that it times out on nonexistent files, even though it should just start the next iteration of the loop. It will successfully read all files up to a point where it can't find one. I then eventually get this error:
Fatal error: Maximum execution time of 30 seconds exceeded in D:\FoxServ\www\php\filename.php on line 33
And I should point out that line 33 is the beginning of the loop. I've only posted the PHP, as I figure the rest is a waste of space.
Code: Select all
<?php
$today = date("mdy");
$filename = "lotd".$today.".html";
$filemonth = date("m");
$fileday = date("d");
$fileyear = date("y");
$run = "0";
while ($filemonth.$fileday.$fileyear != "092703") {
if (file_exists($filename)) {
echo "<tr><td></td><td>";
$run++;
if ($run > "1"){
echo "<hr>";
}
echo "<h4>";
echo "$filemonth";
echo "/";
echo "$fileday";
echo "/";
echo "$fileyear";
echo "</h4>";
include($filename);
echo "</td></tr>";
$fileday--;
if ($fileday == "00") {
$filemonth--;
$fileday = "31";
}
if ($filemonth == "00") {
$fileyear--;
$filemonth = "12";
}
if ($fileday < "10") {
$fileday = date("d", mktime (0,0,0,$filemonth,$fileday,$fileyear));
}
/* if ($filemonth < "10") {
$filemonth = "0".$filemonth;
}
if ($fileyear < "10") {
$fileyear = "0".$fileyear;
}
*/
$filename = "lotd".$filemonth.$fileday.$fileyear.".html";
} else {
echo "";
}
}
?>Fatal error: Maximum execution time of 30 seconds exceeded in D:\FoxServ\www\php\filename.php on line 33
And I should point out that line 33 is the beginning of the loop. I've only posted the PHP, as I figure the rest is a waste of space.
I realize this is probably a mess of code and could be much simplified, but it gets the job done...so I thought I'd share, and let everyone enjoy my haphazard code.
Code: Select all
<?php
$today = date("mdy");
$filename = "lotd".$today.".html";
$filemonth = date("m");
$fileday = date("d");
$fileyear = date("y");
$run = "0";
$exists = "0";
while ($filemonth.$fileday.$fileyear >= "092703") {
while (file_exists($filename)) {
echo "<tr><td></td><td>";
$run++;
if ($run > "1"){
echo "<hr>";
}
echo "<h4>";
echo "$filemonth";
echo "/";
echo "$fileday";
echo "/";
echo "$fileyear";
echo "</h4>";
include($filename);
echo "</td></tr>";
$fileday--;
if ($fileday == "00") {
$filemonth--;
if ($filemonth == "04" || $filemonth == "06" || $filemonth == "09" || $filemonth == "11") {
$fileday = "30";
}
if ($filemonth == "01" || $filemonth == "03" || $filemonth == "05" || $filemonth == "07" || $filemonth == "08" || $filemonth == "10" || $filemonth == "12") {
$fileday = "31";
}
if ($filemonth == "02") {
$fileday = "28";
}
}
if ($filemonth == "00") {
$fileyear--;
$filemonth = "12";
}
if ($fileday < "10") {
$fileday = date("d", mktime (0,0,0,$filemonth,$fileday,$fileyear));
}
if ($filemonth < "10") {
$filemonth = date("m", mktime (0,0,0,$filemonth,$fileday,$fileyear));
}
if ($fileyear < "10") {
$fileyear = date("y", mktime (0,0,0,$filemonth,$fileday,$fileyear));
}
$filename = "lotd".$filemonth.$fileday.$fileyear.".html";
}
$fileday--;
if ($fileday == "00") {
$filemonth--;
if ($filemonth == "04" || $filemonth == "06" || $filemonth == "09" || $filemonth == "11") {
$fileday = "30";
}
if ($filemonth == "01" || $filemonth == "03" || $filemonth == "05" || $filemonth == "07" || $filemonth == "08" || $filemonth == "10" || $filemonth == "12") {
$fileday = "31";
}
if ($filemonth == "02") {
$fileday = "28";
}
}
if ($filemonth == "00") {
$fileyear--;
$filemonth = "12";
}
if ($fileday < "10") {
$fileday = date("d", mktime (0,0,0,$filemonth,$fileday,$fileyear));
}
if ($filemonth < "10") {
$filemonth = date("m", mktime (0,0,0,$filemonth,$fileday,$fileyear));
}
if ($fileyear < "10") {
$fileyear = date("y", mktime (0,0,0,$filemonth,$fileday,$fileyear));
}
$filename = "lotd".$filemonth.$fileday.$fileyear.".html";
}
?>Sorry, I wasn't clear. What I meant was for the decrement of $fileday to appear only once, but outside of the if. i.e.:
Forgive me for not showing this fully using your code, but I'm lazy 
Code: Select all
while(evaluates_true)
{
if(somethingtrue)
{
do_this
}
else
{
do_this
}
$fileday-- etc...
}