Define ('discuz _ root', substr (dirname (_ file _), 0,-7 ));
This is a constant that defines the Forum installation root directory in discuz. Now let's analyze this simple but practical constant.
First describe this articleArticleAssume that the absolute path of the common. Inc. php file is F: \ webroot \ BBS \ include \ common. Inc. php.
This sentence is included in discuz's include/common. Inc. php. First, let's take a look at the value of the constant discuz_root: F: \ webroot \ BBS \
Next we will analyze this sentence in detail:
Define (), of course, is to define a constant. Here it is to define a constant named discuz_root.
Substr (), which is a string truncation function. If substr ('100', 0,-2) is returned, 123456789 is returned.
Dirname (_ file _) ,__ file _ is a magic constant. This is what we say in the manual:"
The complete file path and file name. If it is used in a include file, the include file name is returned. Starting from PhP 4.0.2, __file __
It always contains an absolute path, and earlier versions sometimes contain a relative path. ". Dirname (), returns the directory part in the path. In this case, dirname (_ file _) is the obtained F: \ webroot \ BBS \ include string.
It can be seen that define ('discuz _ root', substr (dirname (_ file _), 0,-7); isF: \ webroot \ BBS \ includeThis string minus the string with the last seven letters:F: \ webroot \ BBS \
If the include folder is changed to Lib,-7 should be changed to-3. Do you understand it?
LaterProgramThis can be written when the file is referenced inRequire_once discuz_root. './test. php'; the actual content of this sentence isRequire_onceF: \ webroot \ BBS \./Test. php