black_thunder Posted August 3, 2009 Share Posted August 3, 2009 This function is part of a news script, and its output currently shows all files in the folder, including the .htaccess file, which I do not want shown as part of the news. The script's WSIWYG editor saves the files as *.txt files, then uses this script to call them and display them. function getNewsList(){ $fileList = array(); // Open the actual directory if ($handle = opendir("admin/news")) { // Read all file from the actual directory while ($file = readdir($handle)) { if (!is_dir($file)) { $fileList[] = $file; } } } rsort($fileList); return $fileList; } How can I use this existing function to retrive only .txt files? Link to comment https://forums.phpfreaks.com/topic/168673-solved-how-to-use-this-function-to-only-output-txt-files/ Share on other sites More sharing options...
WolfRage Posted August 3, 2009 Share Posted August 3, 2009 Take a look at this and see if it helps you out. Trust me it will help you out, but you need to read it through. http://www.phpfreaks.com/forums/index.php/topic,259701.0.html Link to comment https://forums.phpfreaks.com/topic/168673-solved-how-to-use-this-function-to-only-output-txt-files/#findComment-889808 Share on other sites More sharing options...
MatthewJ Posted August 3, 2009 Share Posted August 3, 2009 <?php function getNewsList(){ $fileList = array(); $files = glob("admin/news/*.txt"); foreach($files as $file) { $parts = explode("/", $file); $fileList[] = $parts[2]; } rsort($fileList); return $fileList; } ?> That should do it for you Link to comment https://forums.phpfreaks.com/topic/168673-solved-how-to-use-this-function-to-only-output-txt-files/#findComment-889825 Share on other sites More sharing options...
black_thunder Posted August 3, 2009 Author Share Posted August 3, 2009 @Wolfrage: Sorry, but I dont see anything in there that would help me. I looked at the PHP manual for the PHP function opendir, and the comments following, and I see code that people have made to show only files with a specific ending, but I cant figure out how to tie it in to the existing script...I dont want to break the script that relies on this function... @MatthewJ: I'll try that and post results. Thanks! Link to comment https://forums.phpfreaks.com/topic/168673-solved-how-to-use-this-function-to-only-output-txt-files/#findComment-889832 Share on other sites More sharing options...
black_thunder Posted August 3, 2009 Author Share Posted August 3, 2009 It worked! Thanks! Link to comment https://forums.phpfreaks.com/topic/168673-solved-how-to-use-this-function-to-only-output-txt-files/#findComment-889834 Share on other sites More sharing options...
MatthewJ Posted August 3, 2009 Share Posted August 3, 2009 No problem Link to comment https://forums.phpfreaks.com/topic/168673-solved-how-to-use-this-function-to-only-output-txt-files/#findComment-889840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.