Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/73812-sorting-with-a-glob-function/
Share on other sites

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..

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.

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>";
}
?>

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

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.

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.