Php 多个basename()扩展

Php 多个basename()扩展,php,Php,我们有: $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($p

我们有:

$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]
,但我的服务器不支持PHP5.2。

我想这样就可以了

preg_match('/[\/]*([^\/]+)\.([^\.]+)$/i', $file, $match);
//$match[1] -> the result
//$match[2] -> the extension
如果您使用PHP>5.2.0

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

有很多解决办法。告诉我们你需要什么样的特殊任务,并找到最合适的solution@Col.Shrapnel只需要获取文件名,不带扩展名。请再试一次。有很多任务需要这样做。例如,如果您需要glob(),那么以_array()的方式执行pathinfo()+将是愚蠢的。你需要什么?@Col.Shrapnel我会将这个字符串的值推送到array(),然后回显somewhereWorks,但是太有趣了,是否可以将basename()与多个扩展名一起使用?该死,这是一个逻辑解决方案。我是编程新手,有时觉得自己像头驴子。如果你已经在使用pathino(),为什么还需要basename()<代码>回显路径信息($path,pathinfo_FILENAME)
$info = pathinfo('/www/awesomepath/index.php');
$name = $info['filename']; //index