例如,我如何得到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 >

其他回答

$image_path = "F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map";
$arr = explode('\\',$image_path);
$name = end($arr);

basename()在处理中文等亚洲字符时出现错误。

我用这个:

function get_basename($filename)
{
    return preg_replace('/^.+[\\\\\\/]/', '', $filename);
}

您可以使用basename()函数。

我已经使用函数PATHINFO创建了一个数组的部分路径供您使用!例如,你可以这样做:

<?php
    $xmlFile = pathinfo('/usr/admin/config/test.xml');

    function filePathParts($arg1) {
        echo $arg1['dirname'], "\n";
        echo $arg1['basename'], "\n";
        echo $arg1['extension'], "\n";
        echo $arg1['filename'], "\n";
    }

    filePathParts($xmlFile);
?>

这将返回:

/usr/admin/config
test.xml
xml
test

这个函数从PHP 5.2.0开始就可以使用了!

然后你就可以根据需要操纵所有部件了。例如,要使用完整路径,你可以这样做:

$fullPath = $xmlFile['dirname'] . '/' . $xmlFile['basename'];
<?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 >