note 64908 added to function.file-exists

From: Date: Sat, 22 Apr 2006 20:35:29 +0000
Subject: note 64908 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-109070@lists.php.net to get a copy of this message
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". ---- Server IP: 64.71.164.2 Probable Submitter: 65.188.161.27 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.file-exists.php Edit -- http://master.php.net/note/edit/64908 Del: integrated -- http://master.php.net/note/delete/64908/integrated Del: useless -- http://master.php.net/note/delete/64908/useless Del: bad code -- http://master.php.net/note/delete/64908/bad+code Del: spam -- http://master.php.net/note/delete/64908/spam Del: non-english -- http://master.php.net/note/delete/64908/non-english Del: in docs -- http://master.php.net/note/delete/64908/in+docs Del: other reasons-- http://master.php.net/note/delete/64908 Reject -- http://master.php.net/note/reject/64908 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#109070) next »