Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question How To Show Name of Page Being Viewed?

    I did a search but didn't find anything here. Is there a single command to show the name of the page you are viewing?

    For example, if you have a page named 'menu.php' is there a command that will show ONLY the page name without showing the directory it's in?

    I tried both of these:

    $_SERVER['SCRIPT_NAME']

    $_SERVER['PHP_SELF']

    but they also show the name of the folder the page is in, like this: /demo/menu.php

    I want to only see: menu.php

    I have a code that fixes this, but I want to know if there is a built-in command that does the same thing without having to use a small script?
    Last edited by Phred; 11-23-2011 at 07:35 PM. Reason: Resolved

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    http://php.net/basename

    Here are some alternatives, as I have found that PHP_SELF or SCRIPT_NAME are not always available.

    This code would go in the file being loaded:
    PHP Code:
    $file_name basename__FILE__ ); 
    Or using $_SERVER['REQUEST_URI'] if you'd like to call for the name anywhere (within an included file, etc):
    PHP Code:
    list( $file_uri ) = explode'?'$_SERVER['REQUEST_URI'] );
    $file_name        basename$file_uri ); 
    Last edited by kbluhm; 11-23-2011 at 10:12 PM.

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Thumbs up

    Bingo! That's perfect!

    I wrote this: echo basename(__FILE__);

    +1!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •