Home > php教程 > php手册 > body text

php 获取文件扩展名

WBOY
Release: 2016-06-13 11:23:08
Original
959 people have browsed it

php 获取文件扩展名
曾经需要获得简单地从一个文件末尾的文件扩展名?这可以与pathinfo()函数,但更

需要的是点在这种情况下也。虽然pathinfo()为扩展名,它不会返回点。想到那是在

一个php3早期版本中创建的这一职能,是保持和留给历史的目的。两种方法都提供了乐

趣。

/*** example usage ***/
$filename = 'filename.blah.txt';

/*** get the path info ***/
$info = pathinfo($filename);

/*** show the extension ***/
echo $info['extenstion'];

?>

第二种方法也基本相同以上,但使用字符串操作获得延长和争夺点(.)字符也。


/*** example usage ***/
$filename = 'filename.blah.txt';

echo getFileExtension($filename);

/**
*
* @Get File extension from file name
*
* @param string $filename the name of the file
*
* @return string
*
**/
function getFileExtension($filename){
  return substr($filename, strrpos($filename, '.'));
}
?>


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!