calrockx Posted September 28, 2008 Share Posted September 28, 2008 Cool forum, I'm sure I'll be checking this one often, being the PHP "newb" I am, ha. Anyway, I'm working on a page now and I'm using PHP to read the file names in a directory and display those images on a page. <?php $handle = opendir ('./sections/'.$_GET[section].'/_categories/'); while (false !== ($file = readdir($handle))) { if($file != "." && $file != ".." && $file != basename(__FILE__)) { echo '<li><img src="'.$file.'"/></li>';}} ?> That script is working just fine now as is - it outputs the file name with extension ("image1.jpg" for example). I'd like to modify to output the file name without the period and file type attached (just "image1"). Any ideas? Link to comment https://forums.phpfreaks.com/topic/126177-using-php-to-read-file-names-in-a-directory/ Share on other sites More sharing options...
Caesar Posted September 28, 2008 Share Posted September 28, 2008 <?php $nuname = preg_replace('/\.[aA-zZ]+/','',$file); ?> Additionally, you can use strrpos() to find the last instance of the "." in the extension, if you anticipate using periods in image names. Link to comment https://forums.phpfreaks.com/topic/126177-using-php-to-read-file-names-in-a-directory/#findComment-652472 Share on other sites More sharing options...
calrockx Posted September 28, 2008 Author Share Posted September 28, 2008 Thanks a lot, Caesar that sure did the trick Link to comment https://forums.phpfreaks.com/topic/126177-using-php-to-read-file-names-in-a-directory/#findComment-652500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.