basename() As A str_replace()

<?php

print basename('I made a catastrophe', 'astrophe');
// pfious ... disaster avoided ?

?>

The useless tip of the day is to use basename on any string, to remove unwanted last characters.

The official use is to remove the extension on the file name, but since paths are actually strings, it works. Just avoid strings with / character in them.

See Also

PHP Features

Last updated: 17 July 2026