Usage of basename function in php: [basename($file)]. The basename() function is used to return the file name part of the file path. The function syntax is [basename(path,suffix)], where the parameter path represents the path to be checked.
php basename() function syntax
(Recommended tutorial: php video tutorial)
Function: Return the file name part of the path.
Syntax:
basename(path,suffix)
Parameters:
path Required. Specifies the path to be checked.
suffix Optional. Specifies the file extension. If the file has suffix, this extension will not be output.
Description:
Returns the file name part of the path.
php basename() function usage example
<?php $file = "/phpstudy/WWW/index.php"; echo basename($file);//带有文件扩展名 echo "<br>"; echo basename($file,'.php'); //去除文件扩展名 ?>
Output:
index.php index
The above is the detailed content of How to use the basename function in php. For more information, please follow other related articles on the PHP Chinese website!