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

omg picture omg · Sep 13, 2009 · Viewed 370.5k times · Source

For example, how do I get Output.map

from

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

with PHP?

Answer

Mark Rushakoff picture Mark Rushakoff · Sep 13, 2009

You're looking for basename.

The example from the PHP manual:

<?php
$path = "/home/httpd/html/index.php";
$file = basename($path);         // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
?>