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] Link to comment https://forums.phpfreaks.com/topic/22300-display-file-starting-with-letter/ 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] Link to comment https://forums.phpfreaks.com/topic/22300-display-file-starting-with-letter/#findComment-99893 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 Link to comment https://forums.phpfreaks.com/topic/22300-display-file-starting-with-letter/#findComment-99911 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.