Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2008, 06:42 AM   PM User | #1
spok61438
New Coder

 
Join Date: Sep 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
spok61438 is an unknown quantity at this point
Sorting alphabetically

PHP Code:
<?
$dir 
"music/";
unset(
$param);
if (
is_dir($dir)) {
    if (
$dh opendir($dir)) {
        while ((
$file readdir($dh)) !== false) {
            if (
$file != ".." && $file != "." && strstr($file,"mp3")) {
                if (
$param == "") {
                    
$param "music/" rawurlencode($file);
                } else {
                    
$param .= "|" "music/" rawurlencode($file);
                }
            }
        }
        
closedir($dh);
    }
}
?>
What should I add to the script to make it sort the files alphabetically?

Thanks in advance!
spok61438 is offline   Reply With Quote
Old 02-26-2008, 09:14 AM   PM User | #2
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
try http://php.net/sort
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 02-26-2008, 09:28 AM   PM User | #3
JimM
New Coder

 
Join Date: Jun 2007
Posts: 28
Thanks: 5
Thanked 0 Times in 0 Posts
JimM is an unknown quantity at this point
Something like this asort(),
bad thing is upper case will come before lower (i believe) IE A, B, C, a, c, e

PHP Code:
    function GetDL($dir) {
        
$dl = array();
        if (
$hd opendir($dir)) {
            while (
$sz readdir($hd)) {
                if (
preg_match("/^\.\.?$/",$sz) || is_dir($dir.$sz)) { continue; }
                
$dl[] = $sz;
            }
            
closedir($hd);
        }
        
asort($dl);
        return 
$dl;
    } 
Note: it is an array that is being sorted $dl
JimM is offline   Reply With Quote
Old 02-26-2008, 03:43 PM   PM User | #4
spok61438
New Coder

 
Join Date: Sep 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
spok61438 is an unknown quantity at this point
any one else?
spok61438 is offline   Reply With Quote
Old 02-26-2008, 04:05 PM   PM User | #5
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
dude, what's wrong with sort from #2?
matak is offline   Reply With Quote
Old 02-26-2008, 05:33 PM   PM User | #6
spok61438
New Coder

 
Join Date: Sep 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
spok61438 is an unknown quantity at this point
PHP Code:
<?php

$fruits 
= array("lemon""orange""banana""apple");
sort($fruits);
foreach (
$fruits as $key => $val) {
    echo 
"fruits[" $key "] = " $val "\n";
}

?>
what part should I include in array?
spok61438 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:22 AM.


Advertisement
Log in to turn off these ads.