How do I get a file name from a full path with PHP?

后端 未结 14 2425
花落未央
花落未央 2020-11-22 10:56

For example, how do I get Output.map

from

F:\\Program Files\\SSH Communications Security\\SSH Secure Shell\\Output.map

14条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 11:21

    The basename function should give you what you want:

    Given a string containing a path to a file, this function will return the base name of the file.

    For instance, quoting the manual's page:

    
    

    Or, in your case:

    $full = 'F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map';
    var_dump(basename($full));
    

    You'll get:

    string(10) "Output.map"
    

提交回复
热议问题