View Full Version : Variable for Pagename

04-05-2003, 10:59 PM
How do you make a PHP variable that is equal to the page name (e.g. index.php) also is it possible to make one that is just equal to the file name without the extension (e.g. index)

04-06-2003, 12:09 AM

echo $_SERVER["PHP_SELF"];


04-06-2003, 11:14 PM
does that get name only or name and extension?

04-06-2003, 11:46 PM
That will give you file name and extension.

04-07-2003, 02:30 AM
Or you could just echo $PHP_SELF, am I right? :-)

04-07-2003, 03:04 AM
Actually now that I read more carefully, PHP_SELF will also output the path. Here is a functoin posted at php.net that removes the path and file extension:

function filename() {
$host = $_SERVER['PHP_SELF'];
$i = strlen ($host);
while (($stop!=1) and ($i>=0)) {
if ($host[$i] != "/") {
$new = $host[$i] . $new;
} else $stop=1;
$new = explode ('.', $new);
return $new[0];

Just call the function whenever you want the filename without extension.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum