Archive

Posts Tagged ‘PHP’

PHP – regular expression get filename and extension


//this function will return extension of file name supplied
function getFilename($filename){
    preg_match("/^(.+?)(\.([^\.]*))?$/", $f, $matches);
    return $matches;
}

//how to use
print_r(getFilename('test.txt'));

/* output
array('text.txt', 'test', '.txt', 'txt');
*/

Categories: PHP Tags: ,