avo Posted September 27, 2006 Share Posted September 27, 2006 Hi Allive been playing with directory functionsok i can open the files in a directory and view them but how would i only view the ones starting with a or Amy code is [code]<?//Open directory$dir = opendir("./directory name");//List files in images directorywhile (($file = readdir($dir)) !== false) { echo "filename: " . $files . "<br />"; } closedir($dir);?>[/code] Quote Link to comment Share on other sites More sharing options...
fooDigi Posted September 27, 2006 Share Posted September 27, 2006 add this if statement[code]<?//Open directory$dir = opendir("./directory name");//List files in images directorywhile (($file = readdir($dir)) !== false) { if(ereg ("^[Aa].*", $file)) echo "filename: " . $files . "<br />"; } closedir($dir);?>[/code] Quote Link to comment Share on other sites More sharing options...
avo Posted September 27, 2006 Author Share Posted September 27, 2006 Hi Thank you been think about that for ages i was trying at first to do strpos() but this works great this is what i ended up with [code]<?//Open directory$dir = opendir("./coupon");//List files in images directorywhile (($file = readdir($dir)) !== false) { if (ereg ("^[Aa].*", $file)){ $replace=str_replace(".php","",$file); echo "<a href='coupon/$file'> " . $replace . "</a><br />"; } } closedir($dir); ?>[/code]Thanks Appriciated Quote Link to comment 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.