PHPdirname () function

Source: Internet
Author: User
PHPdirname () function definition and usage
The dirname () function returns the directory part of the path.

Syntax
Dirname (path) parameter description
Path is required. Specifies the path to be checked.

Description
The path parameter is a string containing a full path pointing to a file. This function returns the directory name after the file name is removed.

Example

Echo dirname ("c:/testweb/home. php ");
Echo dirname ("/testweb/home. php ");
?>


Output:

C:/testweb
/Testweb

Php defines a very useful constant, that is

_ FILE __

This internal constant is the complete path (path + file name) of the current php program ).

Even if this FILE is referenced by another FILE (include or require), __file _ is always the complete path of the FILE where it is located, rather than the full path of the FILE that references it.

See the following example:

/Home/data/demo/test/a. php

Echo dirname ("c:/testweb/home. php ");
Echo dirname ("/testweb/home. php ");
?>

Home/data/demo/B. php

Echo dirname ("c:/testweb/home. php ");
Echo dirname ("/testweb/home. php ");
?>


Simply put:
_ FILE _ return current path + FILE name
Dirname (_ FILE _) returns the path of the current FILE path.
Dirname (_ FILE _); the directory name (excluding the last "/" number) at the top of the FILE is obtained)

For example, if the current file is/home/data/demo/test. php
The complete path is/home/data/demo/test. php.
Dirname (_ FILE _) to obtain the path section/home/data/demo (no "/" number is displayed later)

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.