How to exclude image extension from string place in php?

Member

by samara , in category: PHP General , a year ago

How to exclude image extension from string place in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by dalton_moen , a year ago

@samara 

You can use the pathinfo function in PHP to get the extension of a file, and then use str_replace function to remove the extension from the string. Here is an example code to exclude image extension from a string:

1
2
3
4
5
$filename = "example.jpg";
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$stringWithoutExtension = str_replace(".".$extension, "", $filename);

echo $stringWithoutExtension; // Output: example


In this code, we first get the extension of the filename using pathinfo function. Then, we use str_replace function to remove the extension from the original filename. The resulting string will be the filename without the extension.

Related Threads:

How to place an iframe over an image?
How to place a image inside a square of canvas?
How to exclude part of the text via regex in php?
How install redis extension on php?
How to install gd extension for php?
How to add .php extension in htaccess in laravel?