supamastadan Posted June 9, 2008 Share Posted June 9, 2008 Hello. As an introduction, my name is Dan, and I am by no means an expert in php. In fact, my php experience has consisted of me modifying free, creative licensed scripts to meet my needs and learn as I go. That being said, it's worked up untill this point. And while I've searched for an answer online, I haven't quite figured out the solution to my prediciment and hope that fresh eyes and deeper PHP experience will find something simple and easy that I haven't thought of. So with no further adue, here we go... I have a directory with a collection of image files in it. All of which are labeled in a date format. I.E. 2008-02-25.jpg. What I'm trying to do is take each of those files and make those dates values in an array, to be used to link dates on a calendar. I managed to get a script that will print the file names properly. <?php $dirname = "strips"; $dh = opendir( $dirname ) or die("couldn't open directory"); while (!(( $file = readdir( $dh ) ) === false ) ) { if ( is_dir( "$dirname/$file" ) ) print ""; $mod = substr_replace ($file, "", 10, 4); print "$mod<br>"; } closedir( $dh ); ?> Ok... so this is where greenhorn-ness shines through. While the print displays correctly modified strings, I have no clue how to make each file name a value in an array. Is the code I have even the most efficient way to go about doing this? I'm sure there are others, maybe even better ones. Let me know what you think. Thanks a lot for your help and have a nice day. - Dan Link to comment https://forums.phpfreaks.com/topic/109453-solved-i-want-to-turn-filenames-into-values-in-an-array/ Share on other sites More sharing options...
MatthewJ Posted June 9, 2008 Share Posted June 9, 2008 <?php $dirname = "strips"; $dh = opendir( $dirname ) or die("couldn't open directory"); while (!(( $file = readdir( $dh ) ) === false ) ) { if ( is_dir( "$dirname/$file" ) ) print ""; $mod = substr_replace ($file, "", 10, 4); print "$mod<br>"; $newArray[] = $mod; } closedir( $dh ); ?> That should work... I have tried to go back in a few times and add code tags.. but the quick edit feature does not seem to like that idea. Hope that helps Link to comment https://forums.phpfreaks.com/topic/109453-solved-i-want-to-turn-filenames-into-values-in-an-array/#findComment-561414 Share on other sites More sharing options...
supamastadan Posted June 9, 2008 Author Share Posted June 9, 2008 That's perfect! Thanks so much. I had a feeling it was something simple that I just didn't know about. Have a good day. - Dan Link to comment https://forums.phpfreaks.com/topic/109453-solved-i-want-to-turn-filenames-into-values-in-an-array/#findComment-561433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.