How To Get File Name Only Without The Path Slashes In PHP



How To Get File Name Only Without The Path Slashes In PHP
How To Get File Name Only Without The Path Slashes In PHP
Post Description:
Post Tags: how, to, get, file, name, only, without, the, path, slashes, in, php
This Post Has Been Viewed 114 Times Since Fri Feb 29, 2008 10:05 pm Posted By hostman with 1 replies
Next Post »» how to get directory path only without file name in PHP
How To Get File Name Only Without The Path Slashes In PHP
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']);
?>

Leave Your Comments     [ dejar commentarios ]
  * Name     [nombre]

  * eMail (will not be published)     [coreo electronico]

* Enter Your Reply or Comments:    [commentarios]


Add Picture To Comments         [incluir foto]
YES NO             upload
Receive Replies on my Comments (An email will be sent to you when someone replies to your comments)

     

Comments and replies About How To Get File Name Only Without The Path Slashes In PHP




:: 1 :: #45250 - Reply By Joeri On Thu Mar 13, 2008 2:10 am
creative. just, would this not be easier:

echo basename($_server['request_uri'])