Rechercher le fichier nommé numériquement le plus élevé - Astuces CSS

Anonim
$latest = getNewest("/path/to/folder/*_bla.xml"); function getNewest($xmlfile)( foreach (glob($xmlfile) as $filename) ( $c = explode('_', basename($filename)); $files($c(0)) = $filename; ) ksort($files, SORT_NUMERIC); $latest = array_pop($files); if (file_exists($latest))( return $latest; ) return false; )

Dans un dossier se trouvent des fichiers nommés:
1_bla.xml
2_bla.xml

34_bla.xml

La fonction renvoie le fichier avec le plus grand nombre numérique:
$ latest = "/chemin/to/folder/34_bla.xml";