(PHP 3, PHP 4 )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 新加的。
说明
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 新加的。
<?php
$string="http://192.168.0.1/city/test.doc";
$pattern1="(.*)://";
$host=ereg_replace($pattern1,"",$string);
list($name1,$name2,$name3)=split("[/]",$host,3);
echo $name3;
?>
$theString="http://192.168.0.1/city/test.doc";
preg_match_all("|(?:)?\w+\.\w+|",$theString,$theFile);
echo $theFile[0][2]?>
说明
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 新加的。
或者你参看手册里的pathinfo
$path = "/home/httpd/html/index.php";
$file = basename ($path); // $file is set to "index.php"
$file = basename ($path,".php"); // $file is set to "index"
?>
$str="G:\citynet\document\统计方式.txt";
$file=basename($str);
echo $file;
?>
<input type="file" name="userfile2" size="40" style="font-size:9pt"><?
if ($userfile2!="")
{
$str2=basename($userfile2);
$new_name2 = 'upfiles/'.$str2;
$file_dest2 = $new_name2;
//-------------上传文件---------------
@copy($userfile2,$file_dest2))
}
可我取到的$file_dest2 是php1981.tmp