Home  >  Article  >  Backend Development  >  Detailed explanation of the usage of php basename() function to obtain file name

Detailed explanation of the usage of php basename() function to obtain file name

怪我咯
怪我咯Original
2017-05-24 11:38:313792browse

We talked about using the php pathinfo() function to return file path information. The php dirname() function returns the directory part of the file path. This article mainly introduces the use of php basename() functionReturn the

part of the file name in the path.

php basename() function syntax is as follows:

basename(path,suffix)

Parameter details:

Parameters Description
path Required. Specifies the path to be checked.
suffix Optional. Specifies the file extension. If the file name has a file extension, this extension will not be displayed.

Description:

php basename() function gives a full name containing a pointer to a file. Path string, this function returns the basic file name. If the filename ends with suffix, this part will also be removed. In Windows, both slash (/)

and backslash (\) can be used as directory separators. In other environments, it is a slash (/)

Example

<?php
$path = "www/testweb/home.php";

//显示文件名和文件扩展名
echo basename($path) ."<br/>";

//显示文件名没有文件扩展名
echo basename($path,".php");
?>

Code explanation:

Our first echo is used without suffix The parameter returns information with the file name and file extension, while the two echoes contain the suffix parameter php, so the file name is returned without the extension.

The result of running the code is as follows:

Detailed explanation of the usage of php basename() function to obtain file name

[Recommended related articles]:

1. Detailed explanation of the php pathinfo() function to obtain file path information

2.Detailed explanation of the usage of the php dirname() function to obtain file information

The above is the detailed content of Detailed explanation of the usage of php basename() function to obtain file name. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn