Return filename component of path
by Sanju[ Edit ] 2010-01-03 16:58:33
Return filename component of path
The function basename() will return the base name of the file.
$path = "/home/hiox/html/index.php";
$file = basename($path); // $file is set to "index.php"
echo "$file";
?>
The above code will display the base name with the extension.
Result :
index.php
$path = "/home/hiox/html/index.php";
$file = basename($path, ".php"); // $file is set to "index"
echo "$file";
?>
The above code will display only the base name without extension.
Result :
index