say that the url of a page is http://www.blahblah.com/joe.php

is there anyway i can echo out the current filename on that page..

example:

on joe.php show something like this:

Blah blah balh the current filename of this page is joe.php

??/

Thanks in advance.

    it's stored in global var $PHP_SELF , but with complete path...
    use strrpos "/" in case

      You can also use

      echo basename($_SERVER[PHP_SELF]);
      

      if you just want the file and not the complete path.

        I've never seen $_SERVER['PHP_SELF'] before...how is that different from just $PHP_SELF?

        Also, if the file is going to be inside a subdirectory, I think you need to use the basename() function if you just want the file name.

          The values of $SERVER['PHP_SELF'] and $PHP_SELF are the same. The difference between them is the availability and scope. The $PHP_SELF variable won't be available (i.e. won't be defined) if register_globals is off in the php.ini file. If register_globals is off, you'll have to use $SERVER, $GET, $POST, etc. Also, $SERVER, $GET, $_POST, etc are superglobals. i.e. before you had to do

          function func() {
          global $PHP_SELF;
          print $PHP_SELF;
          }

          But now you can just do

          function func() {
          print $_SERVER['PHP_SELF'];
          }

          In other words, you don't have to tell PHP that $_SERVER is a global variable.

          Diego

            Write a Reply...