Home  >  Article  >  Web Front-end  >  php basename function

php basename function

黄舟
黄舟Original
2016-12-15 11:09:061425browse

Let’s take a look at the tutorial below to provide an example of the basename function that is a component of the file path

basename
(PHP 4, PHP 5)

basename - returns the components of the file path

Description
String basename (String $path[, string $suffix])
Given a string containing the path to the file, this function will return the base archive name.

Parameters

Path
A path.

In Windows, both slash ( / ) and backslash ( ) serve as directory separators. In other environments, it is a forward slash ( / ).

Suffix
If the file name ends with a suffix, it will also be cut off.


Return Value
Returns the path specified by the base name.

Modify

Version Notes
The suffix parameter of 4.1.0 is added


Example

For example # 1 basename ( ) example

$path = "/home/httpd/html/index.php" ;
$file = basename($path); // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
? >

The above is the content of the php basename function. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


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