Jump to content

Recommended Posts

the following is a bit of code from a module that creates a list from the contents of a folder... how do I get it to sort the contents alphanumerically before outputting the text?

 

$dh = opendir($name_subdir);

while(gettype($file = readdir($dh))!=boolean){

if ($file != '..' && $file != '.'){

$current_element = $name_subdir.$file;

if(is_dir($current_element)){

read_dir($current_element);

$text .=CreatePlaylist($current_element);//Create playlist from current folder and add to output

}

}

}

closedir($dh);

return $text;

 

Link to comment
https://forums.phpfreaks.com/topic/142248-solved-readdir-alphanumeric-sort/
Share on other sites

I'm using php 5.28 - I just don't have any idea how to program - I using a shareware CMS (e107) and just know enough to hack a few things to make it work like I want.  could you be so kind to post the fix to the above code?  I just don't know enough about php to get where you're going with scandir and arrays.  My knowledge is about as deep as "Why can't I just do sort($text) before it gets returned?

I'm using php 5.28 - I just don't have any idea how to program - I using a shareware CMS (e107) and just know enough to hack a few things to make it work like I want.  could you be so kind to post the fix to the above code?  I just don't know enough about php to get where you're going with scandir and arrays.  My knowledge is about as deep as "Why can't I just do sort($text) before it gets returned?

 

You can't just sort($text) because $text is a string.  sort is for sorting a list of strings, not a single string. The way you have your code setup, it's building a string by pasting the new file name to the end of the string, so you're doing for example

 

$text = "a";

$text = "ab";

$text = "abc";

etc...

 

but then again...if you are not using at least PHP5, i would look into upgrading :)

 

meh.  unless you're heavy into oop, there isn't anything significant in php5 that you can't live without or at least mimic, in php4.  And even if you're heavy into oop, there's still workarounds for a lot of the stuff.  In short, it really isn't that big of a deal.  Now, when php6 is released, then I'd for sure say you need to upgrade, as a lot of deprecated stuff in php4 will be gone.

sorry I offended. thought I made it clear I'm not a programmer.

 

I'm not offended.  I was just telling you how it works around here in a non-sugar coated, dull and boring way.  I'm not a mechanic.  Does that mean I can take my car somewhere and get it fixed for free?  We are willing and happy to help you work through something if you are making an effort to work through it. 

 

You made it pretty clear that you were a beginner.  You didn't really specify whether you were trying to learn or don't care about programming, you just want it done.  If you aren't a programmer and don't really have a desire to get into it...well, that's when you pay someone else to do it for you.

trying to learn, mostly by reverse-engineering existing modules.  still hurts my head.  oh for the glory days when you wrote a basic program and then saved it to your tape recorder!  I actually found the solution to my problem. it was farther down the script after an e_QUERY that I could sort the data.  so if someone wants to mark this thread as solved that would be fine.

trying to learn, mostly by reverse-engineering existing modules.  still hurts my head.  oh for the glory days when you wrote a basic program and then saved it to your tape recorder!  I actually found the solution to my problem. it was farther down the script after an e_QUERY that I could sort the data.  so if someone wants to mark this thread as solved that would be fine.

 

You have to do that, bottom left hand corner above the "Quick Reply".

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.