This article mainly introduces how to obtain the file name and extension in php. I think it is quite good. I will share it with you and give you a reference. Let's take a look at the small Editor. This article mainly introduces the php method for getting file names and extensions. The small editor thinks it is quite good. I will share it with you and give you a reference. Let's take a look at it with Xiaobian.
Php obtains the file name and extension.
1. basename ()-returned path file name
See the following php code:
"; // If suffix is selected, the echo basename ($ path,". php ") extension is ignored.?>
Running result:
Index. php
Index
2. dirname ()-returns the file path of the current script!
Php code:
Running result:
F: \ web \ zend \ exercise
3. pathinfo () returns an associated array containing path information.
It includes the following array units: path name dirname, file name basename, and extension name extension.
See the following simple code demonstration:
"; Echo" File name: $ pathinfo [basename]
"; Echo" extension: $ pathinfo [extension] ";?>
Running result:
Directory name:/usr/www/html
File name: index. php
Extension: php
4. realpath -- returns the normalized absolute path name.
The php code is as follows:
Note the following tips: file path operators in different paths may be different. in windows, "/" and "\" can be used "\",
Only "/" can be used in linux, so we recommend that you use "/" during development, such as the file path above!
The above is all the content in this article. I hope it will help you learn and support the first PHP community.