Understanding of define (' Discuz_root ', substr (DirName (__file__), 0,-7));

Source: Internet
Author: User
Tags function prototype

About define (' Discuz_root ', substr (DirName (__file__), 0,-7)); Understanding define (' Discuz_root ', substr (DirName (__file__), 0,-7)) ;
Get site root directory
For the above statement has not understood what is meant to check the relevant information a little closed

First: This statement consists of three functions of define (), substr (), DirName ()

1. Define ()
Define and use the Define () function to define a constant. Constants are similar to variables, except that:
    • After setting, the value of the constant cannot be changed
    • Constant name does not need to start with dollar sign ($)
    • Scope does not affect access to constants
    • A constant value can only be a string or a number
Grammar define (name,value,case_insensitive)                          Parameters              Description                              name             required. Specifies the name of the constant.                              value             required. Specifies the value of the constant.                              case_insensitive                        

Necessary. Specifies whether the name of the constant is case sensitive.

If set to true, the case is not sensitive. The default is False(case sensitive).


Note: The third parameter is also today seen in the function prototype, define can also set the sensitivity of the case.

2.dirname (path )
Definition and usage Pathparameter is a string that contains a full path to a file. This function returns the name of the directory after the file name has been removed.
Syntax string dirname (string path)
Parameters
Describe
Path
Necessary. Specifies the path to check.
Example <?php
Echo dirname ("c:/testweb/home.php");
Echo dirname ("/testweb/home.php");
?>

Output:

C:/testweb
/testweb
3.substr () function
Define and use the substr () function to return part of a string
Grammar string substr (string $string, int $start [, int $length])

Parameters
Description string Required.                            A string that specifies the part to return. Start

Necessary. Specifies where to start the string.

    • Positive number-starts at the specified position in the string
    • Negative number-starts at the specified position from the end of the string
    • 0-Starts at the first character in a string
Charlist

Optional. Specifies the length of the string to return. The default is until the end of the string.

    • Positive number-returns from the position where the start parameter is located
    • Negative-returns from the end of the string
Note: if Startis negative and lengthLess than or equal Start, you lengthis 0

4.__file__

The path to the __file__ is the full path to the file (not the URL) where the current code resides, so the definition profile is typically placed at the root of the site to define the root address

Define (' Discuz_root ', substr (DirName (__file__), 0,-7));

Assuming __file__ is/home/web/include/common.php
So
The return value of DirName (__file__) is/home/web/include

The return value of substr (DirName (__file__), 0,-7) is/home/web/

Define (' Discuz_root ', substr (DirName (__file__), 0,-7));
is to define the commonsense Discuz_root value of/home/web/

Why is-7???
Yes, because they all happen to be in the Include folder, the number of letters, exactly 7 ...
The constant defined is exactly the absolute address of the root directory ....

Understanding of define (' Discuz_root ', substr (DirName (__file__), 0,-7));

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.