Rineru Posted October 18, 2007 Share Posted October 18, 2007 I'm using this script: <?php foreach(glob('*.swf') as $fn){ $t = str_replace("_","", $fn); echo ' <a href="' . $fn . '">' . ucfirst(substr($t, 0, -4)) . "</a><br>"; } ?> To create a list of games, well it works. GREAT... except one thing I thought it would alphabetize the games automatically, it kinda does. I want the script to do it, completely. Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/ Share on other sites More sharing options...
MadTechie Posted October 18, 2007 Share Posted October 18, 2007 what about this <?php $file = array(); foreach(glob('*.swf') as $fn) { $file[] = $fn; } sort($file); foreach($file as $f) { $t = str_replace("_","", $f); echo ' <a href="' . $f . '">' . ucfirst(substr($t, 0, -4)) . "</a><br>"; } ?> Not prefect.. but works.. i rarely use glob.. Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-372365 Share on other sites More sharing options...
Rineru Posted October 20, 2007 Author Share Posted October 20, 2007 I tried it, and still there is like 3 different alphabetized. Look here: http://www.ayudeg.com/games Don't really expect to see anything good. Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-373713 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Based off php.net <?php $_foo ='/server/public_html/path/'; function s_glob($dir){ $files = array(); if(is_dir($dir)){ if($dh=opendir($dir)){ while(($file = readdir($dh)) !== false){ $files[]=$dir.$file; }} } return $files; } print_r(s_glob($_foo)); ?> is going to be faster than using the glob function. Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-373715 Share on other sites More sharing options...
Rineru Posted October 20, 2007 Author Share Posted October 20, 2007 The quickness isn't my problem, That script works fine, but doesn't alphabetize all the output completely. And I tried that and all that appears is: "Array ()." Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-374345 Share on other sites More sharing options...
MadTechie Posted October 20, 2007 Share Posted October 20, 2007 but doesn't alphabetize all the output completely. it looks like your running it on more than one folder.. as for businessman332211(php.net), function.. yes it returns an array.. your just need to add something like this to the returned data sort($files); foreach($files as $f) { $t = str_replace("_","", $f); echo ' <a href="' . $f . '">' . ucfirst(substr($t, 0, -4)) . "</a><br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-374351 Share on other sites More sharing options...
Rineru Posted October 20, 2007 Author Share Posted October 20, 2007 That didn't work too, All I want is in the first code, sorted... MadTechie, If you truly want to help me, PM me please. Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-374376 Share on other sites More sharing options...
igor berger Posted October 21, 2007 Share Posted October 21, 2007 Here is a sort function from php.net <?php $fruits = array("lemon", "orange", "banana", "apple"); sort($fruits); reset($fruits); while (list($key, $val) = each($fruits)) { echo "fruits[" . $key . "] = " . $val . "\n"; } ?> http://jp2.php.net/manual/fi/function.sort.php Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-374382 Share on other sites More sharing options...
Rineru Posted October 21, 2007 Author Share Posted October 21, 2007 Here is a sort function from php.net <?php $fruits = array("lemon", "orange", "banana", "apple"); sort($fruits); reset($fruits); while (list($key, $val) = each($fruits)) { echo "fruits[" . $key . "] = " . $val . "\n"; } ?> http://jp2.php.net/manual/fi/function.sort.php I'm using the Glob function, not an array. If you can tell me how to array files from a file list with no file extension and sorted, plus uppercase words. I'll do it. Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-375102 Share on other sites More sharing options...
BlueSkyIS Posted October 21, 2007 Share Posted October 21, 2007 glob function returns an array. should be sortable. i don't see results on the page linked. Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-375106 Share on other sites More sharing options...
Rineru Posted October 22, 2007 Author Share Posted October 22, 2007 I fixed it, I was trying another script. Quote Link to comment https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/#findComment-375121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.