Search code examples
phpfilefile-exists

how to check if file something(a number).php exists?


Say I have all these files in a folder:

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

Now I need to somehow check if any something.php file exists (ignoring the number).

so if something(a_number).php exists in the folder, return true...

Any ideas on how I'd do something like this?


Solution

  • You can use glob(), which returns an array of directory contents matching a wildcard pattern.

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