how to get file name only without the path slashes in PHP
RegisterLogin
how to get file name only without the path slashes in PHP
Post Description: how to get file name only without the path slashes in PHP
Tags: how, to, get, file, name, only, without, the, path, slashes, in, PHP
This Post Was Posted On Feb 29, 2008 By web hosting #1319
Post Description: how to get file name only without the path slashes in PHP
Tags: how, to, get, file, name, only, without, the, path, slashes, in, PHP
This Post Was Posted On Feb 29, 2008 By web hosting #1319
how to get file name only without the path slashes in PHP by web hosting
if i have a file called gallery.php and its in the /forums/gallery.php directory, i dont want the forums part.
well, i figure it.
if i use: $_SERVER['PHP_SELF']
print $_SERVER['PHP_SELF'];
OUTPUT:
/forums/gallery.php
if i have gallery.php?id=23: $_SERVER['REQUEST_URI']
print $_SERVER['REQUEST_URI'];
OUTPUT:
/forums/gallery.php?id=23
but i only want gallery.php
this is how i did it
i broke it down to an array:
<?
function GetFileName($php_self){
$filename = explode("/", $php_self); // THIS WILL BREAK DOWN THE PATH INTO AN ARRAY
$filename = array_reverse($filename ); // THIS WILL MAKE THE LAST ELEMENT THE FIRST
return $filename[0];
}
echo GetFileName($_SERVER['PHP_SELF']);
?>
function GetFileName($php_self){
$filename = explode("/", $php_self); // THIS WILL BREAK DOWN THE PATH INTO AN ARRAY
$filename = array_reverse($filename ); // THIS WILL MAKE THE LAST ELEMENT THE FIRST
return $filename[0];
}
echo GetFileName($_SERVER['PHP_SELF']);
?>
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
Joeri
#1747 1
creative. just, would this not be easier:
echo basename($_server['request_uri'])
echo basename($_server['request_uri'])
Mar 13, 2008 Reply Report abuse
©2011 Webune Forums - Thu Dec 22, 2011 11:56 am
Powered by: Webune Forums V3
Powered by: Webune Forums V3