basename ( ) - Returns the base name of a file or path


Syntax:

 basename(file_path);

Project structure:

tutorial/
┣ assets/
┃ ┗ myfile.txt
┗ index.php


Example:

<?php

$file = "assets/myfile.txt";
echo basename($file); //myfile.txt

// Using two parameters, the second to cut the suffix
echo basename($file, ".txt"); //myfile

?>

output:

myfile.txt
myfile