Category Archives: php-basename()

PHP- basename()

The basename() file system function in PHP will return the base name of the file or path you point it at. You can use this function with one parameter or two. The first parameter is the target file or path, and the second is the suffix. If the base name ends with a suffix you may choose to remove it using the second parameter.
Here is the Example:

$file = “myproject/filename.txt”;
// Using one parameter
$baseName = basename($file);
echo $baseName;

echo ”
“;
// Using two parameters, the second to cut the suffix
$baseName = basename($file, “.txt”);
echo $baseName;
?>
OUTPUT:
filename.txt
filename