list files from folder, only one for each date


Posted on 16th Feb 2014 07:03 pm by admin

I have many files in a folder and wish to only list one of each date

these are the file names.
date format (dd/mm/yyy)

abc - 12-01-2009 - something.pdf
abc - 12-01-2009 - something else.pdf
abc - 12-01-2009 - another title.pdf
abc - 24-05-2009 - some other text
abc - 24-05-2009 - yet more files
abc - 24-05-2009 - yet another title.pdf

if i had these files then i would like the results to be

12-01-2009
24-05-2009

in an array


at present i have this script..

Code: $files = glob('agendas/*.pdf');
$sortfile = array();
foreach($files as $file){
//Extract date
if (preg_match('/(d+)-(d+)-(d+)[^.]*?.pdf/', $file, $reg)) {
//if (preg_match('/(d+)-(d+)-(d+)-Agenda Item (d+)[^.]*?.pdf/', $file, $reg)) {
//add date to array (file as key)
$sortfile[$file] = mktime(0,0,0,$reg[2],$reg[1],$reg[3]);
}
}

this only gets the files but i would like to have these files sorted and have only one of each date

how would this be done.

No comments posted yet

Your Answer:

Login to answer
311 Like 42 Dislike
Previous forums Next forums
Other forums

PHP Code / Script To check weather the given email exists in a domain
Hi,

I want to implement the following in my web page

in sign up we will ask to enter u

How to ask a regex question?
Hi, I thought I'd share some of my insight after seeing too many bad questions that either get ignor

Referential Integrity problem when inserting into 2 tables at same time
Hello Everyone,

Im relativity new to PHP and MySQL and i have come up against a problem. i h

Transaction variant for VA02 not working
My requirement is to have transaction for user to only add the output and print a sales order.

Get keys and values from an array
Hellow,

I have an array $Data with keys and values. With a foreach I can display all the valu

Xacute search within SQL results
I have a query that is pulling data, and I want to return a specific value from the results of that

Stats of viewers
Hello. I have a website in php and people can login. I want to make an admin control panel where u c

Will this protect from mysql injection?
I do not want anything like DROP TABLE to work or any type of coding..

Heres my code.. is it

Facebook status update API
Hello,

So, I'm trying to create my first Facebook application with PHP.

Basic ideas fo

Delete Client 066 Earlywatch
Hi all,

in former times client earlywatch was required for SAPs remote access to SAP inst

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash