I would like to use the current file name in a test condition in my php.
For Example:
if ('current page' == editprofile.php) {
// some code;
}
How do I test this?
Thanks
Use basename() in conjuction with the __FILE__ constant.
if(basename(__FILE__) == "editprofile.php") {
// some code;
}
It might even be faster to use stripos
if you're looking for raw speed like so...
if(stripos(__FILE__, "editprofile.php") !== false) {
// Some Code
}
As this page explains, you need to use __FILE__
The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.
Those are so called magic constants, which provide information about the context. On that page you can find all valid constants.
Because it contains a full path, you still have to process this value:
$filename = basename(__FILE__);