PHP Case Insensitive Version of file_exists()

后端 未结 14 1499
忘掉有多难
忘掉有多难 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:11

    AbraCadaver's answer with +7 rating is incorrect, I do not have enough reputation to comment under it, so here is correct solution, based on his answer:

    $result = count(preg_grep('/\/'.preg_quote($filename)."$/i", glob("$path/*")));
    

    AbraCadaver's answer is incorrect, because it returns true if you test against file foo.jpg and files like anytext_foo.jpg exist.

提交回复
热议问题