Get filename from a path with basename() in PHP

Description

The following code shows how to get filename from a path with basename().

Example


/*from ww  w .ja  v a 2  s  .  c om*/
<?php
    $path = "c:/testweb/home.php";

    //Show filename with file extension
    echo basename($path) ."<br/>";

    //Show filename without file extension
    echo basename($path,".php");
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




Directory
DirectoryIterator
Drive
File
File Permission
File Read Save
FileSystemIterator
Path
Zip