I have this code that adds filenames to an Array. When I display the file names they are like this. sample.gif. I just want to be able to display the filename without the extension. so instead of sample.gif if would be able to print just sample to the browser.
if($auto_find=='1'){ //declare array of photos $photos=array(); $pd=opendir($photo_dir); //loop through files while(gettype($pfile=readdir($pd))!=boolean){ $phext=substr($pfile, -3); //if jpg, gif, png-add to array if(($phext=="gif")||($phext=="jpg")||($phext=="png")){ array_push($photos,$pfile); } }//END PHOTO-DIR LOOP FOR FILES closedir($pd);
I already answered your question in the other thread, actually.
I did a quick test and as far as I can tell,
$example = "sample.gif"; $example = preg_replace("/(.*).(gif)$/i", "$1", $example);
should give you want you're looking for.
This works great now how do I add .jpg and .png
$filename = $filename.".jpg";
$example = preg_replace("/(.*).(gif|jpg|png)$/i", "$1", $example);