我们有:
$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。
发布于 2010-08-11 14:21:34
$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发布于 2010-08-11 14:16:57
我想这个就行了
preg_match('/[\/]*([^\/]+)\.([^\.]+)$/i', $file, $match);
//$match[1] -> the result
//$match[2] -> the extensionhttps://stackoverflow.com/questions/3455692
复制相似问题