faqts : Computers : Programming : Languages : PHP : Common Problems : Variables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 10 people (100%) answered Yes
Recently 8 of 8 people (100%) answered Yes

Entry

One variable in a page should be the filename itself. How to do this?

Jun 20th, 2001 07:22
Philip Olson, Ben Udall, Peter van Beelen,


One can usually find the filename in the predefined variable 
$PHP_SELF.  Check your server settings with phpinfo() to be sure then 
consider using the basename() function :
    http://www.php.net/manual/function.basename.php
Here's an example straight out of the manual :
    $path = "/home/httpd/html/index.php3";
    $file = basename ($path); // $file is set to "index.php3"
Using $PHP_SELF as opposed to $path should do the trick.  For more 
information on predefined variables, have a look here :
    http://www.php.net/manual/language.variables.predefined.php
You may also be interested in PHP's Constants, such as __FILE__, which 
can be read about here :
    http://www.php.net/manual/language.constants.php
Running phpinfo() will tell you which contants and predefined variables 
are available on your server, have fun!