Use the pathinfo() PHP function to remove the file extension from a string.


Example:

<?php

// Initializing a variable with filename 
$file = 'testfile.txt';

// Extracting only filename 
$str = pathinfo($file, PATHINFO_FILENAME);

// Printing the result 
echo $str;
?>

Output:

testfile