ItSolutionStuff.com

How to Get File Name without Extension in PHP?

By Hardik Savani • May 14, 2024
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...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get First and Last Character from String in PHP?

Read Now →

How to Write PHP Code in Laravel Blade?

Read Now →

How to Create Zip Folder and Download in PHP?

Read Now →

PHP MySQL Image Gallery CRUD Example

Read Now →

Laravel Join Query with Comma Separated Column Example

Read Now →

PHP MySQL Highcharts Chart Example

Read Now →

PHP Capture Screenshot of Website from URL Example

Read Now →

PHP Remove Duplicates from Multidimensional Array Example

Read Now →

How to Remove Duplicate Values from Array in PHP?

Read Now →

How to Remove White Space from String in PHP?

Read Now →

How to Check If String is URL or Not in PHP?

Read Now →

How to Convert Object into Array in PHP?

Read Now →

How to access PHP variables in JQuery?

Read Now →