How to remove file extension in PHP

2 Answers

0 votes
function removeExtension($filename) {
    return pathinfo($filename, PATHINFO_FILENAME);
}

echo removeExtension('test.php') . "\n"; 
echo removeExtension('example.a.b.jpj') . "\n"; 

 

/*
run:

test
example.a.b

*/

 



answered Jun 12, 2024 by avibootz
0 votes
function removeExtension($filename) {
    return substr($filename, 0, strrpos($filename, '.'));
}

echo removeExtension('test.php') . "\n"; 
echo removeExtension('example.a.b.jpj') . "\n"; 

 

/*
run:

test
example.a.b

*/

 



answered Jun 12, 2024 by avibootz
...