note 74919 deleted from function.readdir by tularis

From: Date: Sun, 13 May 2007 18:58:04 +0000
Subject: note 74919 deleted from function.readdir by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126489@lists.php.net to get a copy of this message
Note Submitter: vbludov \a\t gmail dot com ---- // To keep things simple and short, you can use regex (Regular Expressions) to match list of complex filenames. Be creative! <?php if ($handle = opendir('./')) { while (false !== ($file = readdir($handle))) { if (preg_match("/\.ttf$|\.html$|\.txt$/i", $file)) { echo "$file\n<br>"; } } closedir($handle); } ?> // Here is more regex examples // All files except the ones that start from . and .. // !preg_match("/^\.{1,}/", $file) // All files with extensions html, txt, ttf // preg_match("/\.ttf$|\.html$|\.txt$/i", $file) // All file names which named by numbers only // preg_match("/^\d{1,}/", $file) // All file names that look like dates such as 2007-05-03 // preg_match("/^\d{4,4}-\d\d-\d\d/", $file)

« previous php.notes (#126489) next »