I'm a bit confused as to what you mean by posting the list into a text field (do you want to print_r the list?). But an easy, efficient (I think) way to do this is strrpos().

<?php

function sort_extensions($a, $b) {
  $apos = ($pos = strrpos($a, '.')) ? (strlen($a) - $pos) : 0;
  $bpos = ($pos = strrpos($b, '.')) ? (strlen($b) - $pos) : 0;
  if ($apos == $bpos) {
    return 0;
  }
  return $apos < $bpos ? -1 : 1;
}

$files = array('test.zip',
               'test.gz',
               'test.z',
               'test.jpeg',
               'test.jpg',
               'test');
usort($files, 'sort_extensions');
echo '<pre>';
print_r($files);
echo '</pre>';

?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to