How to use the basename function in php

藏色散人
Release: 2023-04-05 10:26:02
Original
4605 people have browsed it

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

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;); //去除文件扩展名
?>
Copy after login

Output:

index.php
index
Copy after login

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!

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