note 64908 deleted from function.file-exists by cmb

From: Date: Sun, 29 Sep 2019 07:16:45 +0000
Subject: note 64908 deleted from function.file-exists by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212387@lists.php.net to get a copy of this message
Note Submitter: pilotdoofy at gmail dot com ---- I wrote a very simple function that allows you to search a folder for a file name with a regular expression. It can handle both PREG and EREG regexps and can accept different case sensitivities for EREG regexps. function regExpFile($regExp, $dir, $regType='P', $case='') { # Two parameters accepted by $regType are E for ereg* functions # and P for preg* functions $func = ( $regType == 'P' ) ? 'preg_match' : 'ereg' . $case; # Note, technically anything other than P will use ereg* functions; # however, you can specify whether to use ereg or eregi by # declaring $case as "i" to use eregi rather than ereg $open = opendir($dir); while( ($file = readdir($open)) !== false ) { if ( $func($regExp, $file) ) { return true; } } // End while return false; } // End function Basically if you supply anything but "P" for $regType it will assume you're using EREG regexps. The case should only be blank or "i".

« previous php.notes (#212387) next »