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

后端 未结 14 2415
花落未央
花落未央 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:18

    With SplFileInfo:

    SplFileInfo The SplFileInfo class offers a high-level object oriented interface to information for an individual file.

    Ref: http://php.net/manual/en/splfileinfo.getfilename.php

    $info = new SplFileInfo('/path/to/foo.txt');
    var_dump($info->getFilename());
    

    o/p: string(7) "foo.txt"

提交回复
热议问题