Php代码
//方法一:
function extend_1($file_name)
{
$retval="";
$pt=strrpos($file_name, ".");
if ($pt) $retval=substr($file_name, $pt+1, strlen($file_name) - $pt);
return ($retval);
}
//方法二
Php代码
function extend_2($file_name)
{
$extend = pathinfo($file_name);
$extend = strtolower($extend["extension"]);
return $extend;
}
function extend_2($file_name) { $extend = pathinfo($file_name); $extend = strtolower($extend["extension"]); return $extend; }
//方法三
Php代码
function extend_3($file_name)
{
$extend =explode("." , $file_name);
$va=count($extend)-1;
return $extend[$va];
}
function extend_3($file_name) { $extend =explode("." , $file_name); $va=count($extend)-1; return $extend[$va]; }
//方法四
Php代码
function getFileExt($file_name)
{
while($dot = strpos($file_name, "."))
{
$file_name = substr($file_name, $dot+1);
}
return $file_name;
}
?>
function getFileExt($file_name) { while($dot = strpos($file_name, ".")) { $file_name = substr($file_name, $dot+1); } return $file_name; } ?>
另外:
PHP pathinfo() 函数
PHP Filesystem 函数
定义和用法
pathinfo() 函数以数组的形式返回文件路径的信息。
语法
pathinfo(path,options)
参数
描述
path
必需。规定要检查的路径。
process_sections
可选。规定要返回的数组元素。默认是 all。
可能的值:
PATHINFO_DIRNAME - 只返回 dirname
PATHINFO_BASENAME - 只返回 basename
PATHINFO_EXTENSION - 只返回 extension
说明
pathinfo() 返回一个关联数组包含有 path 的信息。
包括以下的数组元素:
[dirname]
[basename]
[extension]
提示和注释
注释:如果不是要求取得所有单元,则 pathinfo() 函数返回字符串。
例子
例子 1
Php代码
// 输出:
// Array([dirname] => /testweb[basename] => test.txt[extension] => txt)
// 输出: // Array([dirname] => /testweb[basename] => test.txt[extension] => txt)
例子 2
Php代码
// 输出:
// test.txt

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version
