How to get filename without extension in PHP?

Today now in this post i will show you how to get filename without extension in PHP? If we need to get the just file name from the url without file extension then we can get that by using basename() php function. Now in the bellow example i will give you how to get the image name without extension. At first we need to get an extension of the given filename url and then basename() through we can remove that extension as like as i did in the bellow:

$imagePath = "/home/hd/html/test.jpg";
$ext = pathinfo($imagePath, PATHINFO_EXTENSION);
$file = basename($imagePath,".".$ext);

Read Also : Laravel 8 Mobile Number Verification Tutorial

Thanks for read. I hope it help you. For more you can follow us on facebook


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →