Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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: 10 September 2026