TXT File + Array Help

I need some help displaying information from a text file by date.

Here is the format of the text file:

2011-06-09 12:54:02;Gold-Bears                  ;Record Store                ;Are You Falling in Love?    
2011-06-09 12:47:20;Chosen Seed                 ;Sacred Animals              ;Welcome Home                
2011-06-09 12:44:41;More Songs About Chocolate a;The Undertones              ;The Very Best of The Underto

Here is the PHP code that displays the previous 15 songs.

[php]

<?php print "
"; $fileArray=file("../../recenttracks.txt"); $songCount = count($fileArray); print ""; print ""; for($i=0; $i<$songCount && $i<15; $i++) { $outputVar = $i + 1; $currentTrack=$fileArray[$i]; $trackArray=explode(";",$currentTrack); $time = date('g:ia', strtotime($trackArray[0])); if($i == 0) print ""; if($i != 0) print ""; } print "

Played

Artist Name

Song Title

Album

" . $time . " " . $trackArray[2] . " " . $trackArray[1] . " " . $trackArray[3] . "
" . $time . " " . $trackArray[2] . " " . $trackArray[1] . " " . $trackArray[3] . "
"; ?>

[/php]

What I need to be able to do is have the ability to display all the tracks played for a specific date.

I would like to be able to display all tracks for today, yesterday, and the day before ONLY.

Could you shed some light?

Thanks :slight_smile:

You can just have it so that if the datetime is more than 48 hours old, it will not display -

if(time()-strtotime($trackArray[0]) < 172800)

[code]<?php
print “
”;
$fileArray=file("…/…/recenttracks.txt");
$songCount = count($fileArray);

print “

”;
print “”;

for($i=0; $i<$songCount && $i<15; $i++)
{
$outputVar = $i + 1;
$currentTrack=$fileArray[$i];
$trackArray=explode(";",$currentTrack);
$time = date(‘g:ia’, strtotime($trackArray[0]));
if(time()-strtotime($trackArray[0]) < 172800)
{
if($i == 0)
{
print “

”;
}
if($i != 0)
{
print “”;
}
}
}

print “

Played

Artist Name

Song Title

Album

” . $time . “ ” .
$trackArray[2] . “
” . $trackArray[1] . “ ” . $trackArray[3] . “
” . $time . “ ” .
$trackArray[2] . “
” . $trackArray[1] . “ ” . $trackArray[3] . “
”;

?>[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service