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

怪我咯
Release: 2023-03-07 21:18:02
Original
3810 people have browsed it

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)
Copy after login

Parameter details:

ParametersDescription
pathRequired. Specifies the path to be checked.
suffixOptional. 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");
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template