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
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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.