且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP,获取没有文件扩展名的文件名

更新时间:2021-12-13 07:56:49

不需要所有这些.查看 pathinfo(),它给出你的道路的所有组成部分.

No need for all that. Check out pathinfo(), it gives you all the components of your path.

手册中的示例:

$path_parts = pathinfo('/www/htdocs/index.html');

echo $path_parts['dirname'], "
";
echo $path_parts['basename'], "
";
echo $path_parts['extension'], "
";
echo $path_parts['filename'], "
"; // filename is only since PHP 5.2.0

代码输出:

/www/htdocs
index.html
html
index

或者,您只能获得某些部分,例如:

And alternatively you can get only certain parts like:

echo pathinfo('/www/htdocs/index.html', PATHINFO_EXTENSION); // outputs html