例如,我如何得到output。map
from
F:\程序文件\SSH通信安全\SSH安全Shell\Output.map
使用PHP吗?
例如,我如何得到output。map
from
F:\程序文件\SSH通信安全\SSH安全Shell\Output.map
使用PHP吗?
当前回答
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"
?>
或者,在你的情况下:
$full = 'F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map';
var_dump(basename($full));
你会得到:
string(10) "Output.map"
其他回答
basename()在处理中文等亚洲字符时出现错误。
我用这个:
function get_basename($filename)
{
return preg_replace('/^.+[\\\\\\/]/', '', $filename);
}
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"
?>
或者,在你的情况下:
$full = 'F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map';
var_dump(basename($full));
你会得到:
string(10) "Output.map"
为了从URI中获得确切的文件名,我将使用以下方法:
<?php
$file1 =basename("http://localhost/eFEIS/agency_application_form.php?formid=1&task=edit") ;
//basename($_SERVER['REQUEST_URI']); // Or use this to get the URI dynamically.
echo $basename = substr($file1, 0, strpos($file1, '?'));
?>
$image_path = "F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map";
$arr = explode('\\',$image_path);
$name = end($arr);
SplFileInfo:
SplFileInfo类提供了一个高级的面向对象 到单个文件的信息的接口。
裁判:http://php.net/manual/en/splfileinfo.getfilename.php
$info = new SplFileInfo('/path/to/foo.txt');
var_dump($info->getFilename());
或/ p:管柱(7)“foo。txt”