Powered by Discuz Learn how to discuz PHP to introduce files Discuz_root

Source: Internet
Author: User
Tags php introduction
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. Since 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)); is F:\webroot\bbs\include this string minus the end of the 7-letter string: F:\webroot\bbs\
If the Include folder is changed to Lib then-7 should be changed to 3, do not know you understand it?
Later in the program to refer to the file when you can write the require_once discuz_root. './test.php '; The actual content of this sentence is require_once f:\webroot\bbs\./test.php

The above describes the powered by Discuz Learning Discuz PHP Introduction file method Discuz_root, including powered by Discuz content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.