substr (DirName (__file__))

Source: Internet
Author: User

This is a constant in Discuz that defines the forum installation root directory. Now let's analyze this simple but very practical constant. Define (' Discuz_root ', substr (DirName (__file__), 0,-7));
This is a constant in Discuz that defines the forum installation root directory. Now let's analyze this simple but very practical constant.
let's start by explaining that the absolute path to the common.inc.php file is assumed to be F:\webroot\bbs\include\common.inc.php in this article.
This sentence is contained in the include/common.inc.php of Discuz, first we look at the value of the constant discuz_root: F:\webroot\bbs\
Next we analyze this sentence specifically:
Define (), of course, defines a constant, and here is a constant that defines a name that is discuz_root.
SUBSTR (), this is the string intercept function, substr (' 123456789 ', 0,-2) This sentence is to return 1234567.
DirName (__file__), __file__ is a magic constant, as the manual says. the full path and file name of the file. If used in the include file, the include filename is returned. From PHP 4.0.2, __file__ always contains an absolute path, and the previous version sometimes contains a relative path. ”。 DirName (), which returns the directory portion of the path. So it seems that dirname (__file__), is F:\webroot\bbs\include a string of strings to get.

Thus define (' Discuz_root ', substr (DirName (__file__), 0,-7)); It is F:\webroot\bbs\includeThis string subtracts the 7-letter string at the end: F:\webroot\bbs\
If the Include folder is changed to Lib then-7 should be changed to 3, do not know you understand it?

You can write this later when you reference a file in a program. require_once Discuz_root. './test.php '; The actual content of this sentence is require_once F:\webroot\bbs\ ./test.php

substr (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.