首页 > php框架 > php 获取文件扩展名

php 获取文件扩展名

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

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

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

趣。

<?php

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

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

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

?>

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


<?php

/*** 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, .));
}
?>


永久地址:http://www.phprm.com/frame/php1004992.html

转载随意~请带上教程地址吧^^

标签:none

发表留言