超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<Filesystemchgrp>
Last updated: Fri, 22 Jun 2007

basename

(PHP 3, PHP 4 , PHP 5)

basename -- 返回路径中的文件名部分

说明

string basename ( string path [, string suffix])

给出一个包含有指向一个文件的全路径的字符串,本函数返回基本的文件名。如果文件名是以 suffix 结束的,那这一部分也会被去掉。

在 Windows 中,斜线(/)和反斜线(\)都可以用作路径分隔符。在其它环境下是斜线(/)。

例子 1. basename() 例子

<?php
$path
= "/home/httpd/html/index.php";
$file = basename ($path);        // $file is set to "index.php"
$file = basename ($path,".php"); // $file is set to "index"
?>

注: suffix 参数是 PHP 4.1.0 新加的。

参见 dirname()




add a note add a note User Contributed Notes
basename
Richard at Lyders dot Net
02-Apr-2003 05:53
you can also make use of the basename() function's second parameter:

<?PHP
$fpath = "/blah/file.name.has.lots.of.dots.ext";
$fext  = array_pop(explode('.', $fpath));
$fname = basename($fpath, '.'.$fext);

print "fpath: $fpath\n
";
print "fext: $fext\n
";
print "fname: $fname\n
";
?>

<Filesystemchgrp>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22