Home >Backend Development >PHP Tutorial >php set_include_path function
The
set_include_path function of php is used to set the application directory. Reasonable application of this function when developing projects allows us to avoid layer-by-layer calculations when including. Directory can also improve the efficiency of our development, reduce the file inclusion error rate, and bring convenience to our PHP project. PHPStudents with poor foundation should take a closer look.
Look at an example
Create 2 new php files, a directory location structure is as follows
/index.php
/include/config.php
index.php Code:
<?php set_include_path("include"); include("config.php"); ?>
/include/config.php Code:
<?php set_include_path("include"); include("config.php"); ?>
Now let's run index.php and see the result. When we include, we only need to write config.php to include the /inlcude/config.php file.
Set multiple include directories Use " ;" to separate them. For example: set_include_path("include;include2;include3;lib;c:/php/lib"); You can use relative paths or relative paths. Maybe you may not feel the benefits of set_include_path in this small code, but it doesn't matter. , you only need to remember that this code can achieve such a function. When you improve your technology in the future, don’t forget to have such a function when developing large-scale projects. It can reduce your workload.
Sister functionget_include_path() can get the include directory at that time. The same function as set_include_path is also achieved by our powerful and lovely ini_set() Usage:
ini_set( 'include_path', 'directory name');
Related recommendations:
Detailed explanation of the usage of set_include_path and get_include_path
The difference between set_include_path under win and linux_PHP tutorial
The above is the detailed content of php set_include_path function. For more information, please follow other related articles on the PHP Chinese website!