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.