note 35129 added to function.glob

From: Date: Wed, 20 Aug 2003 18:04:01 +0000
Subject: note 35129 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-54772@lists.php.net to get a copy of this message
Piping the output of "ls" and parsing that if you don't have glob() handy is kind of a bad hack. Here's a far better implementation that uses normal PHP functions that you will find in < 4.3.0. if ($fp = opendir('.')) { while (($file = readdir($fp)) !== FALSE) { if (is_file($file) && preg_match('/\.txt$/', $file)) { echo "$file\n"; } } closedir($fp); } It's set to return only files, not directories, but you can change that easily by removing the is_file() check. Also, this gives you the extra power of a full regex pattern matcher which glob() may not be able to provide. ---- Manual Page -- http://www.php.net/manual/en/function.glob.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35129 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35129&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35129&report=yes

« previous php.notes (#54772) next »