PHP - Get filename from file path

Published on Aug 11 2016

PHP pathinfo(), returns information about a file path, from php 5.2.0 PATHINFO_FILENAME constant was added which returns the filename from file path with the file extension removed.

example: path/to/file/index.phtml

    // get filename from file path.
    $file = 'path/to/file/index.phtml';
    $filename = pathinfo($file, PATHINFO_FILENAME);
    echo $filename;

returns index


Updated by db Aug 11 2016 , filed under PHP