I recently had the need to determine the exact file name of the current web page within a PHP application. It is simple to retrieve the full URL containing the filename, such as http://www.domain.com/example.php using $_SERVER['PHP_SELF'], but I wanted to parse only the 'example.php' part.
I used two string functions to do this, substr and strrpos. Strrpos finds the last occurrence of "/", and substr parses everything after that. Here's the code:
substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/") + 1)