File name which has "st" in the 3rd and 4th

if(file_exists('test.php')){echo 'yes';}else{echo 'no';}

The code above find whether the file name “test.php” is or not.

I like to find whether a file name which has “s” in the 3rd and 4th is or not.

The following code doesn’t work correctly but I hope it shows what I want.

if(file_exists('S in the 3rd and 4th')){echo 'yes';}else{echo 'no';}

if there is only a file named “test.php” in the folder, it will echo “yes”.
if there is only a file named “moist.php” in the folder, it will echo “no”.
if there is only a file named “past.php” in the folder, it will echo “yes”.
if there is only a file named “study.php” in the folder, it will echo “no”.

How can I check whether there is a file which has “s” in the 3rd, or not?

get all file names, loop through them and test whether the 3rd/4th letter is an s.

if(glob("??st*")) echo 'yes'; else echo 'no';

if you want it case sensitive, and

if(glob("??[sS][tT]*")) echo 'yes'; else echo 'no';

if don’t

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.