Wednesday, September 14, 2022

How to remove extension from string in PHP

 

How to remove extension from string in PHP


There are multiple ways to remove extension from a file name in PHP
 
<?php
  
// Initializing a variable with filename
$file = 'myfilename.jpg';
  
// Extracting only filename using constants
$fileWithoutExt = pathinfo($file, PATHINFO_FILENAME);
  
// Printing the result
echo $fileWithoutExt;
  
?>



Output

filename

No comments:

Post a Comment