The PHP basename () function Gets the use of the file name

Source: Internet
Author: User
We talked earlier about using the PHP pathinfo () function to return the file path information, the PHP dirname () function is the directory part of the return file path, this article mainly introduces the use of php basename () functionReturns the file name in the path

Part.

The PHP basename () function syntax is as follows:

BaseName (Path,suffix)

Detailed parameters:

Parameters Description
Path Necessary. Specifies the path to check.
Suffix Optional. Specifies the file name extension. If the file has a file name extension, this extension will not be displayed.

Description

The PHP basename () function gives a string containing a full path to a file, which returns the basic file name. If the file name ends in suffix, then this part will be removed as well. In Windows, slash (/)

and backslashes (\) can be used as directory separators. Slash (/) in other environments

Example

<?php$path = "www/testweb/home.php";//Display file name and file name extension echo basename ($path). " <br/> ";//display filename does not have file name extension echo basename ($path,". php ");? >

Code Explanation:

Our first echo used without the suffix parameter, returned with the file name and filename extension information, and two echo, with the suffix parameter PHP, so returned is the file name, no extension name.

The result of the code operation is as follows:

"Related articles recommended":

1. Detailed php pathinfo () function get file path information

2. Detailed php dirname () function get file information usage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.