About PHP Get file name basename () function usage

Source: Internet
Author: User
PHP basename () function gives a string containing a full path to a file, this function returns the basic file name, this article collected about the use of PHP basename () function to get the file name of a few articles, I hope to understand that you use PHP basename () function to get the filename is helpful.

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

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 analysis of __file__, dirname and basename usages in 2.PHP

This article uses examples to describe __file__, dirname, and basename usages in PHP. Share to everyone for your reference. The method is as follows: __file__ the full path and file name of the current running file in PHP, and if used in the included file, returns the included file name, which is a magic variable (predefined constant), we can get the file directory or filename by Universal dirname and basename.

3. Use PHP pathinfo (), Parse_url (), basename () function to parse the URL instance explained

PHP functions PathInfo (), Parse_url (), and basename (), these three are all functions that parse the URL, but there are some differences, this article lists some examples, hope that through these examples to help you understand the three functions of the use of methods and techniques, The PathInfo function is the path, directory, or file name that gets the file. The Parse_url () function is used to parse the URL and return an associative array of parsing components, which does not detect whether the URL is legitimate and only resolves it as correctly as possible. The basename () function returns the file name in the path

The difference and example of dirname,basename,pathinfo function in 4.php

The PHP dirname function is to get the directory portion of a given file path, and the PHP basename () function gets the file name portion of the path, which is exactly the opposite of DirName () (DirName gets the directory portion of the path). The PHP pathinfo function parses the path and resolves the path to an array of four values, including the directory name, the full filename, the file extension, and the file name (not including the file suffix), and the key names for the four values are dirname, basename, Extension and filename, we can get the value of the directory name, the full filename, the file extension, and the file name through the four key names. This article mainly introduces to you the difference of these three functions and the usage examples.

"Questions and Answers about the basename () function"

PHP basename get filenames, special symbols will be garbled!

"BaseName Entry"

BaseName

"Related articles recommended"

PHP pathinfo () function get file path Information Usage Summary

PHP dirname () function return file directory Usage Summary

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.