Re: separating a file extention
| From: | Jason Barnett | Date: | Mon, 19 Jul 2004 02:27:09 +0000 |
| Subject: | Re: separating a file extention | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-190963@lists.php.net to get a copy of this message | ||
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>';
?>