How to Get File Name without Extension in PHP?
Hi,
This simple article demonstrates of get image name without extension php. This post will give you a simple example of php remove file extension from path. I explained simply about how to get filename in php without its extension. I explained simply step by step get image name without extension php.
If you need to get only the filename from a URL without the file extension, you can achieve this by using the basename() PHP function. In the example below, I will demonstrate how to obtain the image name without the extension. Firstly, we need to identify the extension of the given filename URL, and then we can use basename() to remove that extension, as demonstrated below:
index.php
<?php
$imagePath = "/home/hd/html/imagefilename.jpg";
$ext = pathinfo($imagePath, PATHINFO_EXTENSION);
$file = basename($imagePath,".".$ext);
print_r($file);
?>
Output:
imagefilename
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get First and Last Character from String in PHP?
- How to Write PHP Code in Laravel Blade?
- How to Create Zip Folder and Download in PHP?
- PHP MySQL Image Gallery CRUD Example
- Laravel Join Query with Comma Separated Column Example
- PHP MySQL Highcharts Chart Example
- PHP Capture Screenshot of Website from URL Example
- PHP Remove Duplicates from Multidimensional Array Example
- How to Remove Duplicate Values from Array in PHP?
- How to Remove White Space from String in PHP?
- How to Check If String is URL or Not in PHP?
- How to Convert Object into Array in PHP?
- How to access PHP variables in JQuery?