Php 使用pathinfo搜索扩展名时允许在文件名中使用点

Php 使用pathinfo搜索扩展名时允许在文件名中使用点,php,filenames,glob,Php,Filenames,Glob,我想使用pathinfo()从文件名中提取扩展名 现在打印时: array(4) { ["dirname"]=> string(33) "E:/folder/some-folder-with.dots" ["basename"]=> string(13) "some-folder-with.dots" ["extension"]=> string(10) ".dots" ["filename"]=> string(2) "some-fold

我想使用
pathinfo()
从文件名中提取扩展名

现在打印时:

array(4) {
  ["dirname"]=>
  string(33) "E:/folder/some-folder-with.dots"
  ["basename"]=>
  string(13) "some-folder-with.dots"
  ["extension"]=>
  string(10) ".dots"
  ["filename"]=>
  string(2) "some-folder-with"
}
我现在使用的代码是:

function rglob($pattern, $flags = 0) {
    $files = glob($pattern, $flags); 
    foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
        $files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
    }
    return $files;
}

$dir = 'E:/folder/*/*.*';
$files = rglob($dir);

# LOOP
foreach($files AS $file) {

    # KONTROLL
    if($file != '.' AND $file != '..') {

        # VARIABEL
        $testing = pathinfo($file);
        $fname = glob($dir.'/*/*.'.$testing['extension']);

        echo '<pre>';
        var_dump($testing);
        echo '</pre>';

    }

}
函数rglob($pattern,$flags=0){ $files=glob($pattern,$flags); foreach(glob(dirname($pattern)。“/*”,glob_ONLYDIR | glob_NOSORT)作为$dir){ $files=array_merge($files,rglob($dir.'/'.basename($pattern),$flags)); } 返回$files; } $dir='E:/folder/*/*.'; $files=rglob($dir); #环路 foreach($files作为$file){ #康特罗尔 如果($file!='.'和$file!='.'){ #瓦里亚贝尔 $testing=pathinfo($file); $fname=glob($dir./*/...$testing['extension']); 回声';
array ( 0 => '/var/www/html/UusProjekt/intl/homepage_template.php', 1 => '/var/www/html/UusProjekt/intl/config.php', 2 => '/var/www/html/UusProjekt/intl/english.php', 3 => '/var/www/html/UusProjekt/intl/spanish.php', 4 => '/var/www/html/UusProjekt/intl/index.php', )
var_dump($测试); 回声';
array ( 0 => '/var/www/html/UusProjekt/intl/homepage_template.php', 1 => '/var/www/html/UusProjekt/intl/config.php', 2 => '/var/www/html/UusProjekt/intl/english.php', 3 => '/var/www/html/UusProjekt/intl/spanish.php', 4 => '/var/www/html/UusProjekt/intl/index.php', )
} } 这段代码的功能是,我想获取一个文件夹中的每个文件,然后获取它找到的每个文件的扩展名,以便为我的网站找到正确的扩展名。就目前而言,我的文件名中不能有我想要的点


如何实现这一点?

您希望从SPL获得DirectoryIterator类

这只是一个示例,您可以使用它,但您可以自定义从中获得的许多内容: