PHP Case Insensitive Version of file_exists()

后端 未结 14 1475
忘掉有多难
忘掉有多难 2020-11-30 07:47

I\'m trying to think of the fastest way to implement a case insensitive file_exists function in PHP. Is my best bet to enumerate the file in the directory and do a strtolowe

14条回答
  •  隐瞒了意图╮
    2020-11-30 08:33

    //will resolve & print the real filename
    $path = "CaseInsensitiveFiLENAME.eXt";
    $dir  = "nameOfDirectory";
    
    if ($handle = opendir($dir)) {
     while (false !== ($entry = readdir($handle))) {
         if (strtolower($path) == strtolower($entry)){
           echo $entry ;
        }}
        closedir($handle);
    }
    

提交回复
热议问题