Description
string
basename ( string path [, string suffix])
Given a string containing a path to a file, this function will
return the base name of the file.
If the filename ends in suffix this will
also be cut off.
On Windows, both slash (/) and backslash
(\) are used as path separator character. In
other environments, it is the forward slash
(/).
Example 1. basename() example $path = "/home/httpd/html/index.php";
$file = basename ($path); // $file is set to "index.php"
$file = basename ($path,".php"); // $file is set to "index" |
|
Note:
The suffix parameter was added in PHP 4.1.0.
See also: dirname()
User Contributed Notes basename |
 |
|
|
dexxter at nothing dot ch
06-Feb-2002 05:42 |
|
to avoid having the object in mem changed, use: $mystring =
basename(strval($file),".ext");
|
|
darianlassan[at]yahoo[dot]de
30-Aug-2002 01:24 |
|
'Get Filename without path and
extension': $filename=current(split("\.",basename($SCRIPT_NAME)));
That's
the shortest one. Right?
|
|
ibyte at SPAMMEANDDIEnoxs dot nl
29-Sep-2002 11:02 |
|
I have a small amendment to darianlassan's 'filename without path and
extension' line:
$filename = current(explode('.',
basename($SCRIPT_NAME)));
As it says on the split()
page: "Note that if you don't require the power of regular
expressions, it is faster to use explode(), which doesn't incur the
overhead of the regular expression engine."
|
|
simon at blueshell dot dk
14-Nov-2002 03:36 |
|
basename() and dirname() both accept a relative path/filename as input.
Example:
print basename('./public_html/index.php'); /* returns
'index.php' here */
|
|
 |