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

后端 未结 14 2419
花落未央
花落未央 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 10:59

    There are several ways to get the file name and extension. You can use the following one which is easy to use.

    $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
    

提交回复
热议问题