如何检查文件是否存在(数字).php?

时间:2012-03-22 18:33:38

标签: php file file-exists

假设我在文件夹中包含所有这些文件:

something(34324).php
something(34).php
something(3433454546).php
something(65565).php
something(9887).php
something(4585).php // ect ect

现在我需要以某种方式检查是否存在任何something.php文件(忽略该数字)。

所以如果文件夹中存在something(a_number).php,则返回true ...

关于我如何做这样的事情的任何想法?

1 个答案:

答案 0 :(得分:8)

您可以使用glob(),它返回与通配符模式匹配的目录内容数组。

$somethings = glob('something*.php');
if (!empty($somethings)) {
    // something exists
}