The basename () function in PHP is a built-in function used to return the base name of a file
Syntax
basename(path, suffix)
Show filename, but cut off file extension for ".jpg" files
#example.php
<?php
$path = "images/pic.jpg";
//Show filename, but cut off file extension for ".jpg" files
echo basename($path,".jpg");
?>
Output:
pic |
Method 2
<?php
$xmlFile = pathinfo('/usr/admin/config/test.xml');
function filePathParts($arg1) {
echo $arg1['dirname'], "\n";
echo $arg1['basename'], "\n";
echo $arg1['extension'], "\n";
echo $arg1['filename'], "\n";
}
filePathParts($xmlFile);
?>
Output:
/usr/admin/config
test.xml xml test |