dstbtam8732
2013-08-17 05:08
浏览 24
已采纳

按字母顺序排序搜索结果

<?php
$searchforfile = "les thugs - 1999 - tout doit disparaitre (lp)  [www.pirate-punk.net].zip";

    $root = $_SERVER['DOCUMENT_ROOT'];
    $search = preg_quote(utf8_decode($searchforfile));


        function rsearch($folder, $pattern) {
            $dir = new RecursiveDirectoryIterator($folder);
            $ite = new RecursiveIteratorIterator($dir);
            $files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);
            $fileList = array();

            foreach($files as $file) {
                $fileList = array_merge($fileList, $file);
            }
            return $fileList;
        }
        $resultatss = rsearch($root, '/.*\/'.$search.'/');

foreach ($resultatss as $resultat) {

        $downloadlink = str_replace("$root/", "", $resultat);
            $za = new ZipArchive();
            $za->open($downloadlink);
            for( $i = 0; $i < $za->numFiles; $i++ ){
                $stat = $za->statIndex( $i );
                $toune = basename( $stat['name'] );
                echo "$toune <br>";
            }


}

?>

This script will list all files inside a ZIP archive then echo the name of each files.

Now i'm having some trouble figuring how to sort the files names ($toune) alphabetically

thanks

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhui1630 2013-08-17 05:09
    已采纳

    Try with asort like

    for( $i = 0; $i < $za->numFiles; $i++ ){
        $stat = $za->statIndex( $i );
        $toune_arr[] = basename( $stat['name'] );        
    }
    asort($toune_arr);
    print_r($toune_arr);
    

    See this LINK

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题