Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple basename() extensions

Tags:

php

We have:

$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

How can we query a multiple file extensions? Instead of

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

something like

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

So, If $path = "/home/image.png"; $file will get value 'image'.

I've tryed to use pathinfo() and [filename], but my server doesn't support PHP 5.2.

like image 340
James Avatar asked Sep 01 '25 16:09

James


1 Answers

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

if you using PHP > 5.2.0

$info = pathinfo('/www/awesomepath/index.php');
$name = $info['filename']; //index
like image 196
Pavel Morshenyuk Avatar answered Sep 04 '25 07:09

Pavel Morshenyuk