Hi there, im making a small function to collect txt files content that is filterd by markdown.
i need to change my code to add a date and time format to the first line (line 0)
my problem is i dont know how to read the date and time from the first line
then use that date and time to sort the files by date time order
then i need to ignore the first line so i can get the content
any help would be great , heres my function…
[php]
function get_media($media_cat, $display_recent) {
global $Parsedown, $media_id;
if (isset($media_id)) {
if ($media_id == $media_cat) {
$display_recent = null;
}
}
$directory = MEDIA_BASEDIR.$media_cat.’/’;
$files = array();
$files = glob($directory.’*.txt’);
usort($files, function($x, $y) {
return filectime($x) < filectime($y);
});
$recent_content = array_slice($files, 0, $display_recent);
foreach ($recent_content as $media) {
$content = file_get_contents($media);
$media_title = basename($media);
$media_title = basename($media, ‘.txt’);
if (file_exists($media)) {
$date_time = date (‘F d Y H:i:s’, filectime($media));
}
THEMEMEDIATOP($media_title, $media_cat);
echo $Parsedown->text($content);
THEMEMEDIABOTTOM($date_time);
}
}
[/php]
i obviousley would have to remove/change
[php]
usort($files, function($x, $y) {
return filectime($x) < filectime($y);
});
[/php]
and the date in the THEMEMEDIABOTTOM function would be the top line of the collected file
and $content would have to be changed to ignore the first line.
im not useing a database because my aim is to be able to upload my txt files to a directory and thats it
then its added to the top as newest first and all i have to do in my text file is add the date and time at the top, should i edit my content i can quickly edit the date and time to bring it to the top or just leave it as is even after editing it
thanks