·历史归档1 分钟阅读
PHP函数---获取文件扩展名/获取文件名
愚者·布尔软件 (Bullsoft) 创始人
原文链接:[http://abeautifulsite.net/2009/03/php-functions-to-get-and-remove-the-file-extension-from-a-string/](http://abeautifulsite.net/2009/03/php-functions-to-get-and-remove-the-file-extension-from-a-string/)
get extension function file_ext()
// Returns only the file extension (without the period).
function file_ext($filename) {
return preg_replace('/^.*\./', '', $filename);
}
get file name function file_ext_strip()
// Returns the file name, less the extension.
function file_ext_strip($filename){
return preg_replace('/\.[^.]*$/', '', $filename);
}
但是,好像PHP也有自带解决方案:
’;
echo file_ext_strip($filename).’’;
?>