Php method for getting file names and extensions _ php instance-PHP source code

Source: Internet
Author: User
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.

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.