PHP define () and dirname (__file__)

Source: Internet
Author: User

The 1,define () function defines a constant. Constants are similar to variables, except that:

(1) After setting, the value of the constant cannot be changed

(2) The constant name does not need to start with the dollar sign ($)

(3) Scope does not affect access to constants

(4) A constant value can only be a string or a number

Grammar
Define (name,value,case_insensitive)

Name, required, specifying constant names; value, required, specified constant value; case_insensitive, optional. Specifies whether the name of the constant is case sensitive. The default is False (case sensitive).

instance, defines a case-sensitive constant and outputs

        Define (' STR ', ' Hello World ');        Echo STR;

Output Hello World

2,dirname (__file__)

DirName (__file__) is the absolute path to the current file, and the lookup speed is the fastest compared to the relative path.
If you repeat the dirname once, you can raise the directory up one level:

The example below assumes that the test.php file is stored in the (d:\www\) directory

        echo __file__;  Obtain the current file absolute address, output D:\www\test.php        echo dirname (__file__);//Get the absolute directory where the current file is located, output D:\www        echo dirname (dirname (__ file__));//Gets the previous level of the directory where the current file is located, Output D:

  

PHP define () and dirname (__file__)

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.