Gazan Posted February 28, 2009 Share Posted February 28, 2009 Hello experts. How do i get all files (.php) from a specefied folder, and store them into an array? Link to comment https://forums.phpfreaks.com/topic/147286-put-all-pages-in-a-folder-into-an-array/ Share on other sites More sharing options...
ratcateme Posted February 28, 2009 Share Posted February 28, 2009 <?php $files = array (); if ($handle = opendir('/path/to/files')) { while (false !== ($file = readdir($handle))) { if(substr($file,strlen($file)-3) == "php"){ $files[] = $file; } } closedir($handle); } print_r($files); ?> adapted from readdir that should do it check the manual for more info Scott. Link to comment https://forums.phpfreaks.com/topic/147286-put-all-pages-in-a-folder-into-an-array/#findComment-773160 Share on other sites More sharing options...
wildteen88 Posted February 28, 2009 Share Posted February 28, 2009 You could you use glob much shorter syntax. $php_files = glob("*.php"); echo '<pre>'.print_r($files, true).'</pre>'; Link to comment https://forums.phpfreaks.com/topic/147286-put-all-pages-in-a-folder-into-an-array/#findComment-773209 Share on other sites More sharing options...
Gazan Posted February 28, 2009 Author Share Posted February 28, 2009 Thanks alot for your replies. Link to comment https://forums.phpfreaks.com/topic/147286-put-all-pages-in-a-folder-into-an-array/#findComment-773504 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.