- Forums
- PHP
- How To Get File Name Only Without The Path Slashes In PHP
This Page Contains information about How To Get File Name Only Without The Path Slashes In PHP By wallpaperama in category PHP with 3 Replies. [1109], Last Updated: Sat May 18, 2024
wallpaperama
Fri Feb 29, 2008
3 Comments
1408 Visits
i saw your post on how to get your path, but what i wanted to do was to only get the file name..
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']);
?>
https://www.wallpaperama.com/forums/how-to-get-file-name-only-without-the-path-slashes-in-php-t5813.html