PHP -Sortierarray nach Nummer im Dateinamen

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: PHP -Sortierarray nach Nummer im Dateinamen

by Anonymous » 16 Feb 2025, 14:38

Ich arbeite an einer Fotogalerie, die die Fotos automatisch basierend auf den Nummern des Dateinamens sortiert. < /p>

Ich habe den folgenden Code: < /p> < Br />

Code: Select all

//calculate and sort
$totaal = 0;
if($handle_thumbs = opendir('thumbs')){
$files_thumbs = array();
while(false !== ($file = readdir($handle_thumbs))){
if($file != "." && $file != ".."){
$files_thumbs[] = $file;
$totaal++;
}
}
closedir($handle_thumbs);
}
sort($files_thumbs);

//reset array list
$first = reset($files_thumbs);
$last = end($files_thumbs);
//match and split filenames from array values - image numbers
preg_match("/(\d+(?:-\d+)*)/", "$first", $matches);
$firstimage = $matches[1];
preg_match("/(\d+(?:-\d+)*)/", "$last", $matches);
$lastimage = $matches[1];
, aber wenn ich Dateinamen wie Photo-Aname_0333.jpg , foto-bname_0222.jpg habe, beginnt es mit dem Photo-Aname_0333 anstelle des 0222 .>

Top