★ wanayoo — archive 1999 http://fr.php.net/manual/fi/function.basename.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previousFilesystemchgrpnext
Last updated: Tue, 28 May 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Czech | Dutch | French | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Slovak | Spanish | Swedish | Turkish

basename

(PHP 3, PHP 4 >= 4.0.0)

basename -- Returns filename component of path

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 (/).

Esimerkki 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"

Huomaa: The suffix parameter was added in PHP 4.1.0.

See also: dirname()

User Contributed Notes
basename
add a note about notes
chopin at csone dot kaist dot ac dot kr
10-Sep-1999 09:48

tailing directory char '/' is ignored in dirname() and basename()

dirname("http://host.net/dir/dir2/")
//"http://host.net/dir"

basename("http://host.net/dir/dir2/")
//"dir2"

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 */

add a note about notes
previousFilesystemchgrpnext
Last updated: Tue, 28 May 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Sat Nov 23 04:10:11 2002 CET