views:

86

answers:

3

I want to do following 2 things 1)i want retrive the list of all files in a directory 2)and then i want to remove their extensions

eg: if i get a list of fils as A.png ,B.png,C.jpeg,D.txt I want to get A,B,C,D

How do i do that in php?

+1  A: 

Check out the glob function for directory listing, and use this for removing the extension:

substr($filename, 0,strrpos($filename,'.')
Zed
+2  A: 
<?php
foreach (new DirectoryIterator('directory') as $fileInfo) {
        if($fileInfo->isDot()) continue;
    $regex = '/\.\w+/';
    echo preg_replace( $regex, '', $fileInfo->getFilename() ) . '<br>';
}
meder
+1 for using the SPL : I don't see it used often enough :-(
Pascal MARTIN
+2  A: 
function filename_part($f) {
    return pathinfo($f, PATHINFO_FILENAME);
}

$result = array_map("filename_part", scandir($directory));
Scott Evernden
thanks for answering:But i get error when i copy pasted ur code in a php file.Error isFatal error: Cannot redeclare basename() in C:\xampp\htdocs\ccare\store_pic.php on line 7
uhh .. ok, call it something else .. change in 2 places
Scott Evernden