Jump to content

Return and Print Last Ten .txt Files


pyrosarco

Recommended Posts

I basically want to make a very simple blog.  I will have a folder for the year called '2008.'  In the folder, I will have text files listed in date order, with the newest being the highest number.  So the names of the text files will appear as  20080214.txt  20080213.txt 20080209.txt  for February 14th, 13th and 9th and so on. 

 

How do I find the last ten largest numbers and return them to be printed in a .php for the web?  I'm thinking the name has to be stored in a string and then appended to something that prints

 

<?php include('folder/filename') ?>

 

 

Thanks,

 

pyrosarco

Link to comment
https://forums.phpfreaks.com/topic/93439-return-and-print-last-ten-txt-files/
Share on other sites

is there a reason you don't want to use a database for your blog? It doesn't make much sense that you wouldn't. I know it's daunting at first, but I promise, it's really easy! :)

 

Here's a way to get the past 10 days, though

 

<?php

#print date("Y-m-d", strtotime("yesterday"));

for ($i=0; $i<10; $i++) { 
        print date("Y-m-d", strtotime("$i days ago")) . "<br>"; 
}


?>

 

Using that method it could be simply modified to do the following:

 

<?php

#print date("Y-m-d", strtotime("yesterday"));

for ($i=0; $i<10; $i++) {
        $year = date("Y", strtotime("$i days ago")) . "<br>";
        $month = date("m", strtotime("$i days ago")) . "<br>";
        $day = date("d", strtotime("$i days ago")) . "<br>";

        print returnPost($year, $month, $day);
}

function returnPost($year, $month, $day) {
        #read file, etc
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.