例如,我如何得到output。map

from

F:\程序文件\SSH通信安全\SSH安全Shell\Output.map

使用PHP吗?


当前回答

<?php

  $windows = "F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map";

  /* str_replace(find, replace, string, count) */
  $unix    = str_replace("\\", "/", $windows);

  print_r(pathinfo($unix, PATHINFO_BASENAME));

?> 

正文,html, iframe { 宽度:100%; 高度:100%; 溢出:隐藏; } < iframe的src = " https://ideone.com/Rfxd0P " > < / iframe >

其他回答

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”

您可以使用basename()函数。

为了在最少的行数内完成这一操作,我建议使用内置的DIRECTORY_SEPARATOR常量以及explosion(分隔符,字符串)将路径分离为多个部分,然后简单地提取所提供数组中的最后一个元素。

例子:

$path = 'F:\Program Files\SSH Communications Security\SSH SecureShell\Output.map'

//Get filename from path
$pathArr = explode(DIRECTORY_SEPARATOR, $path);
$filename = end($pathArr);

echo $filename;
>> 'Output.map'

有几种方法可以获取文件名和扩展名。你可以用下面这个简单易用的。

$url = 'http://www.nepaltraveldoor.com/images/trekking/nepal/annapurna-region/Annapurna-region-trekking.jpg';
$file = file_get_contents($url); // To get file
$name = basename($url); // To get file name
$ext = pathinfo($url, PATHINFO_EXTENSION); // To get extension
$name2 =pathinfo($url, PATHINFO_FILENAME); // File name without extension
<?php

  $windows = "F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map";

  /* str_replace(find, replace, string, count) */
  $unix    = str_replace("\\", "/", $windows);

  print_r(pathinfo($unix, PATHINFO_BASENAME));

?> 

正文,html, iframe { 宽度:100%; 高度:100%; 溢出:隐藏; } < iframe的src = " https://ideone.com/Rfxd0P " > < / iframe >