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__))