Jump to content
  • 0

pomoc Zoradenie podla abecedy


kalixt

Dotaz

Nejaký návrh ako upraviť kod tak aby zoradovalo podla abecedy bez ohladu na velké a malé písmená?

 

Aby to nedopadlo takto: Audi

                                      Bmw

                                      Citroen

                                      aston martin

                                      bentley

 

ale takto: aston martin

                Audi

                bentley

                BMW

                Citroen

 

Tie auta su len ako príklad :d

<?php

$path = 'zložka';
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle))
{
        if($file != '.' && $file != '..')
        {
                $file = substr($file, 0, strpos($file, " ")-4);
                echo"<span style='font-size: 12px; font-family: Tahoma; color: #00FF00;'>$file</span><br />";
        }
}
closedir($dir_handle);

?>
Link to comment
Share on other sites

7 odpovědí na tuto otázku

Recommended Posts

  • 0


<?php
$path = "zložka";
foreach (scandir($path) as $file) 
{
if($file != ".." && $file != ".")
{
$file = substr($file, 0, strpos($file, " ")-4);
echo "<span style='font-size: 12px; font-family: Tahoma; color: #00FF00;'>".$file."</span><br />";
}
}

 

Edited by Pixel
Link to comment
Share on other sites

  • 0

http://php.net/manual/en/function.sort.php

bool sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )

SORT_FLAG_CASE - can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively

 

0.16666 vteriny....

 

<?php

$fruits 
= array(
    
"Orange1""orange2""Orange3""orange20"
);
sort($fruitsSORT_NATURAL SORT_FLAG_CASE);
foreach (
$fruits as $key => $val) {
    echo 
"fruits[" $key ] = " $val "\n";
}


?>

The above example will output:

fruits[0] = Orange1fruits[1] = orange2fruits[2] = Orange3fruits[3] = orange20

Nechapu jak na ofik webu muzou napsat { na radek podminky, to je takova prasarna....

Edited by ATomas
Link to comment
Share on other sites

  • 0

Jo, sorry :d Ještě tam chybí ignorace velkých / malých znaků.

<?php
$path = scandir("zložka");
natcasesort($path);
foreach ($path as $file) 
{
     if($file != ".." && $file != ".")
     {
           $file = substr($file, 0, strpos($file, " ")-4);
           echo "<span style='font-size: 12px; font-family: Tahoma; color: #00FF00;'>".$file."</span><br />";
     }
}
Edited by Pixel
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...