note 92037 added to function.glob

From: Date: Mon, 06 Jul 2009 17:10:50 +0000
Subject: note 92037 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-157975@lists.php.net to get a copy of this message
First off, it's nice to see all of the different takes on this. Thanks for all of the great examples. Fascinated by the foreach usage I was curious how it might work with a for loop. I found that glob was well suited for this, especially compared to opendir. The for loop is always efficient when you want to protect against a potential endless loop. $dir=$_SERVER['DOCUMENT_ROOT']."/test/directory_listing/test"; echo $dir; $filesArray=glob($dir."/*.*"); $line.="<pre>"; $line.=print_r($filesArray, true); $line.="</pre>"; $line.="<hr>"; for($i=0;$i<count($filesArray);$i++) { $line.=key($filesArray)." - "; $line.=$filesArray[$i]."<br/>"; next($filesArray); } echo $line; Note that I pulled the glob array keys if you should need them. Also you can tweak it for searches with something like this... (case sensitive) $search_names="Somedocname"; $filesArray=glob($dir."/".$search_names."*.*"); Enjoy! ---- Server IP: 209.41.74.194 Probable Submitter: 206.57.124.50 ---- Manual Page -- http://www.php.net/manual/en/function.glob.php Edit -- https://master.php.net/note/edit/92037 Del: integrated -- https://master.php.net/note/delete/92037/integrated Del: useless -- https://master.php.net/note/delete/92037/useless Del: bad code -- https://master.php.net/note/delete/92037/bad+code Del: spam -- https://master.php.net/note/delete/92037/spam Del: non-english -- https://master.php.net/note/delete/92037/non-english Del: in docs -- https://master.php.net/note/delete/92037/in+docs Del: other reasons-- https://master.php.net/note/delete/92037 Reject -- https://master.php.net/note/reject/92037 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157975) next »