gpt4 book ai didi

php - 多个 basename() 扩展

转载 作者:行者123 更新时间:2023-12-04 22:11:31 25 4
gpt4 key购买 nike

我们有:

$path = "/home/httpd/html/index.php";
$file = basename($path); // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
$file = 'index'; // the result

我们如何查询多个文件扩展名?而不是

$file = basename($path, ".php");

类似

$file = basename($path, ".php,gif,png,jpeg,css,js,html");

所以,如果 $path = "/home/image.png"; $file 将得到值 'image'。

我尝试使用 pathinfo()[filename],但我的服务器不支持 PHP 5.2。

最佳答案

$file = basename($path);
$info = pathinfo($file);
$name = basename($file,'.'.$info['extension']); // index

如果你使用 PHP > 5.2.0

$info = pathinfo('/www/awesomepath/index.php');
$name = $info['filename']; //index

关于php - 多个 basename() 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3455692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com