Use of include () in PHP

zhaozj2021-02-11  224

Use of include () in PHP

It is often seen that some people ask about the problem of using include () when the file is positioned, which is why: such a file system structure xxxx - | | | -dira- | | | -a.php | | -a2.php | | -Dirb - | | | -b.php

A.php '. CHR (10)); include ('a2.php');?>

A2.php '. Chr (10));?>

B.php

Some people will encounter access to B.PHP error - can't find A2.php, which is very confused to come to the rookie concentration camp 9CBS rivers and lakes. Look at everyone's answer is usually telling innocent asks to check if the PHP.ini is correct in the PHP.INI, whether it contains the current path ("."). I have also made an impatient, now I think it is really ---- sweating! After the PHP is installed, INLCUDE_PATH in php.ini is set to.; C: / PHP / Includes or.: / Php / incdude (UNIX series platform, Linux), you can see all included Current path. In front of the php.ini in some PHP distribution, it is ";" comment, the inlCude_path in the inlcude_path is in this time.; C: / php4 / pear or.: / Php4 / pear ("4" is because I use the PHP version of 4.x). In this way, the problem is usually not on the inlande_path variable (unless Whiteeat is not changed into grandmother! Hey, the grandmother hotel is good, the price is fair, and the price is unbranched. In fact, there is a fact that there is a often ignored fact between everyone and the questioner: PHP version - this time is a small version. In the PHP 4.0.x environment, the above example is unable to run, need to put "include ('a2.php') in A.php;" change to "include ('../ dira / a2.php') ; ", Or copy A2.php into a directory DIRB, which usually does not usually expect - the amount of task is too large. In the PHP 4.2.x (including higher) environments, the above example can pass unimpeded, and the file system structure can also be passed. Clear. The problem is different from the explanation of "." In different versions. In 4.0.x, "." Is only considered (start) the execution path of the script; in 4.2.x, it also contains the path to the current file. From the above example, when importing document A.php, "." Will point to the path DIRB and A.php of the B.PHP to the path DIRA. Writing here, suddenly an issue: If there is a A2.php file in Dirb.php in Dirb.php, then B.PHP will finally import A2.php under which path? I would like to leave this question to the PHP's MM test, then ask them to celebrate the world, but when I think about the time of crushing, the time of the rubbing powder, the time of the polish powder ("a few" is a hundred levels) . The test results show the A2.php below Dirb. Welcome everyone to contribute more such "small" issues to our rookie concentration camp. Note: The above example is equally applicable to the Require method (and later include_once (), request_once ()).

转载请注明原文地址:https://www.9cbs.com/read-5162.html

New Post(0)