ripkjs Posted April 19, 2009 Share Posted April 19, 2009 Looking to grab the contents of a subdir and combine/append the contents of .htm files in that directory, and any new ones added, into one usable string. The .htm files will always be named with the 6 digit MMDDYY.htm, and maximum of only one per day (3-4per week in total). So I think that would eliminate the need to check the file date. I'd like to display the contents of the newest one on top, and descend as the dates get older. With scandir() I can get these files in an array (and in the correct order), but the first two keys are being taken up with "." and "..", and going beyond that, I'm not sure how to get the contents of the items in the array to display. Quote Link to comment https://forums.phpfreaks.com/topic/154718-get-contents-of-a-dir-and-echo-the-contents-of-the-htm-files/ Share on other sites More sharing options...
ripkjs Posted April 20, 2009 Author Share Posted April 20, 2009 Any hints? Quote Link to comment https://forums.phpfreaks.com/topic/154718-get-contents-of-a-dir-and-echo-the-contents-of-the-htm-files/#findComment-814170 Share on other sites More sharing options...
alphanumetrix Posted April 20, 2009 Share Posted April 20, 2009 do you have a code? Quote Link to comment https://forums.phpfreaks.com/topic/154718-get-contents-of-a-dir-and-echo-the-contents-of-the-htm-files/#findComment-814177 Share on other sites More sharing options...
teynon Posted April 20, 2009 Share Posted April 20, 2009 Do basic file directory listings and implement a file name preg match of: if (preg_match("@^\d{6}.htm$@i", $filename)) { // Do some junk. } http://www.php.net/manual/en/function.readdir.php Quote Link to comment https://forums.phpfreaks.com/topic/154718-get-contents-of-a-dir-and-echo-the-contents-of-the-htm-files/#findComment-814182 Share on other sites More sharing options...
alphanumetrix Posted April 20, 2009 Share Posted April 20, 2009 this should help get you started: $dir = 'my directory'; $handle = opendir($dir); $result = array(); while ( $listings = readdir($handle) ) { if ( $listings != '.' && $listings != '..' ) { if ( !preg_match("@^\d{6}.htm$@i", $filename) ) $result[] = $listings; } to display them: foreach ($result as $r) { echo '<li>' . $r . '</li>'; } Quote Link to comment https://forums.phpfreaks.com/topic/154718-get-contents-of-a-dir-and-echo-the-contents-of-the-htm-files/#findComment-814199 Share on other sites More sharing options...
ripkjs Posted April 20, 2009 Author Share Posted April 20, 2009 Perfect! /cheer Quote Link to comment https://forums.phpfreaks.com/topic/154718-get-contents-of-a-dir-and-echo-the-contents-of-the-htm-files/#findComment-814947 Share on other sites More sharing options...
premiso Posted April 20, 2009 Share Posted April 20, 2009 An alternative, and maybe easier method would be to use glob Just thought I would throw that in there. Too lazy to provide an example however since the above worked. Quote Link to comment https://forums.phpfreaks.com/topic/154718-get-contents-of-a-dir-and-echo-the-contents-of-the-htm-files/#findComment-814957 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.