Home >Backend Development >PHP Tutorial >How to use the basename function in php

How to use the basename function in php

藏色散人
藏色散人Original
2019-02-19 15:44:444642browse

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.

How to use the basename function in php

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,&#39;.php&#39;); //去除文件扩展名
?>

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!

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

Related articles

See more