Studiati questo codice:
Codice PHP:
<pre>
<?php
function get_date($string) {
if (preg_match('#_(\\d{2})(\\d{2})(\\d{2})_#', $string, $matches)) {
return $matches[3] . $matches[2] . $matches[1];
}
return false;
}
function mysort($a, $b) {
return strcmp(get_date($a), get_date($b));
}
$files = glob($_CONFIG['path'] . '/*.txt');
/*
// Test
$files = array('pippo_011009_000000.txt', 'pippo_021009_000000.txt', 'pippo_150609_000000.txt');
// */
usort($files, 'mysort');
print_r($files);
?>
</pre>