Friday, February 18, 2011

Get Current File Name using PHP

There are two ways I found to get the current page name using php.

$path = $_SERVER["SCRIPT_NAME"];
$file = basename($path); // $file is set to "myfile.php"
$file = basename($path, ".php"); // $file is set to "myfile"

$currentFile = $_SERVER["SCRIPT_NAME"];
$parts = Explode('/', $currentFile);
$parts = array_reverse($parts);
echo("Script is " . $parts[0]);


Summarizer said...

Thanks for the helpful post. This is what I need!

vehicle wraps orange county said...

This is a great website post. cheers very much for the great insight and we really appreciate the time you took to write this.

CustomWriting said...

so simply!! amazing...two minutes and everithing works well again!! thanks a lot

Orange County Blind Cleaners said...

I think this computer Get Current File Name using PHP is much more effective than the other one.

Post a Comment