How to get a file name without a suffix by php
This article mainly introduces php how to get the file name without suffix, the article is very detailed, has a certain reference value, interested friends must read it!
Get method: 1, use basename () function, syntax "basename (file path, need to remove suffix name)"; 2, use pathinfo () function, syntax "pathinfo (file path, PATHINFO_FILENAME)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The method of getting the file name without suffix by php
1. Use the basename () function
The basename () function returns the filename portion of the path. Syntax:
Basename (path,suffix)
Parameter path: indicates the path to be checked.
Parameter suffix: can be omitted to indicate the file extension. If the suffix parameter is not omitted, the file name without the extension is output.
Example:
Output:
Home.phphome
2. Use the pathinfo () function
The pathinfo () function returns information about the file path as an array. Syntax:
Pathinfo (path,options)
Parameter path: indicates the path to be checked.
The parameter options: can be omitted to indicate the array elements to be returned. The default value is all. You can have the following values:
PATHINFO_DIRNAME: only the directory name (dirname) is returned.
PATHINFO_BASENAME: returns the full file name (basename), that is, the file name with the extension.
PATHINFO_EXTENSION: returns only the extension (extension)
PATHINFO_FILENAME: returns the file name without an extension (filename).
Example:
Output:
Demo above is all the content of the article "how to get a file name without a suffix by php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!