Full-service Internet Marketing & Web Development
Recent Posts

Sponsors
![]() |
newslister phpCode Wizard, 12-30-2006 |
Newslister.php
This newslister is based on another script I've made called File lister.
This scripts collects the filenames in a specified directory and outputs a link to each file with
date and timestamp taken from the filename.
It also outputs a header for each month, so all news during a month is collected on one place.
Its also sorted in descending order, with the newest ads first.
The only variable you would need to change is the $newsdir(use a trailing slash) to get it working.
Ofcourse you can modify the rest of this code, Its opensource. Just be sure that you know what you're doing before messing it up >:)
information warefare: irc.system33r.net
applications: http://teksys.cjb.net/
/*
This is the code I used to create the filenames with. To make it easy I suggest you to make a
small textbox on a page and let the script take care of writing it to a suitable directory.
$fileyear=date(Y);
$filemonth=date(m);
$fileday=date(d);
$filehour=date(H);
$fileminute=date(i);
$filesecond=date(s);
$completefilename="$fileyear-$filemonth-$fileday.$filehour-$fileminute-$filesecond";
*/
Function searchdir($basedir)
{
global $filelisting, $number; //defines the two variables as global so they can be accessed from outside the function
unset($filelisting); //kills $filelisting in case it have been used earlier in the script
unset($number); //same as above
$handle=opendir($basedir);
while ($file = readdir($handle)) {
if ($file=="." or $file=="..") {
} else {
$filelisting[]="$basedir$file";
};
};
$number=sizeof($filelisting); //gets the size of the array
};
//variables to change...
$newsdir="/news/html/"; //Set the path where the newsfiles is located
//stop here
searchdir($newsdir);
$number=$number-1;
sort($filelisting); //sorts the array $filelisting
$otheryear="0"; //sets $otheryear to zero
while($number>="0"){
$file=$filelisting[$number];
$linkfile=$file; //saves the correct path to the linkfile for future use.
$file=ereg_replace( "$newsdir", '', $file ); //Strips the $newsdir from $file
//Script below extracts the correct date and time from the filename
//The script suspects the format of the filename should be Y-m-d.H-m-s for example 1999-08-11.18-00-11
//In case you have an extension(for example .html) on your newsfiles it will be putted in $file[2]
$file=split(".",$file,3); //Splits the $file by the .
$date=split("-",$file[0],3); //splits the date in $file[0] by the -
$year=$date[0]; //year is the first part of the date in $date[0]
$month=$date[1]; //month is the second part of the date in $date[1]
$day=$date[2]; //day is the third part of the date in $date[2]
$time=ereg_replace( '-', ':', $file[1] ); //To make the time string look good you only have to replace the - with :
$number=$number-1; //decrements the variable $number to make the while function to end in a reasonable amount of time
$yearmonth="$year-$month";
if($yearmonth!=$otheryear){
echo "<BR><B><U>";
echo date("F", mktime(0,0,0,$month,1,$year)); //outputs the correct month in characters
echo " $yearmonth[0]";
echo "</U></B><BR>";
echo "<A HREF="$linkfile">$year-$month-$day $time</A><BR>";
$otheryear=$yearmonth; //Makes $otheryear equals to $yearmonth to stop the script from printing headers more than once.
$inc=$inc+1;
}else{
echo "<A HREF="$linkfile">$year-$month-$day $time</A><BR>";
$inc=$inc+1;
}; //end of if statement
}; //end of while statement
?>
|
|
Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments

