【问题标题】:Scandir without file extensions没有文件扩展名的 Scandir
【发布时间】:2013-02-28 22:16:42
【问题描述】:

如何让文件显示没有文件扩展名? 目前我得到一个像logo.png 这样的文件,但我只需要文件名logo

if (is_dir($dir_path)) {

    $files = scandir($dir_path);

    foreach($files as $file) {

        if ( !in_array( $file, $exclude_all ) ) {

            $path_to_file = $dir_path . $file;
            $extension = pathinfo ( $path_to_file, PATHINFO_EXTENSION );
            $file_url = $dir_url . $file;

            echo 'Path to file: ' . $path_to_file . '<br />';
            echo 'Extension: ' . $extension . '<br />';         
            echo 'URL: ' . $file_url . '<br />';

        }
    }
}

【问题讨论】:

    标签: php scandir


    【解决方案1】:

    由于 PHP 5.2.0 pathinfo 也可以做到这一点:

    $bareName = pathinfo($path_to_file, PATHINFO_FILENAME);
    

    【讨论】:

      【解决方案2】:
      $text = "filename.test.php";
      
      echo substr($text, 0, strrpos($text, ".")); //filename.test
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-12-24
        • 2012-12-24
        • 2017-06-27
        • 1970-01-01
        • 1970-01-01
        • 2011-12-28
        • 2018-08-06
        相关资源
        最近更新 更多