Friday, February 18, 2011

Get Current File Name using PHP

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

<?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]);
?>

0 comments:

Post a Comment