Home > Backend Development > PHP Tutorial > php set_include_path function

php set_include_path function

韦小宝
Release: 2023-03-17 17:48:01
Original
1704 people have browsed it

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");   
?>
Copy after login
Copy after login

/include/config.php Code:

<?php  
set_include_path("include");  
include("config.php");   
?>
Copy after login
Copy after login


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:

set_include_path usage

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template