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? Quote 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. Quote 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>'; Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.