The previous article introduced you to "What is the difference between include and require in PHP? What is the difference between Include_once? 》, this article continues to introduce to you what are the two article loading paths in PHP? What is the file path? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
What is the file path?
In the computer, the path points to a file or a text identifier of some content. A slash "\" or "/" is often used to separate each interval. The slash is followed by the previous sub-item.
/: Indicates the root path of the current path.
./: Indicates the current path.
../: Indicates the parent path, the upper-level path where the current path is located.
The loading path of the file includes two categories:.
1. Absolute path
Start from the root directory of the disk (local absolute path).
Windows: drive letter C:/path/PHP file.
Linux: /path/PHP file.
Start from the website root directory (absolute network path).
/: The path corresponding to the website host name.
Localhost/index.phpe -> E:rver/apachedocs/index.php.
2. Relative path: the path starting from the directory where the current file is located.
.1./: Represents the current folder.
../: Upper-level directory (the upper-level folder of the current folder).
The difference between loading absolute paths and relative paths:
1. Absolute paths are relatively inefficient, but relatively safe (the path will not cause problems).
2. Relative paths are relatively more efficient, but prone to errors (relative paths will change).
Let’s take the code as an example:
<?php //被包含的文件 //定义数据 $a = 1; define('PI',3.14); ?>
<?php //PHP文件加载路径 //相对路径加载 include_once 'include1.php'; echo $a ; ?>
The code demonstration results are as follows:
The above code is the default file itself;
File nested inclusion:
One file contains another file, and the included file contains another file.
When nested includes, it is easy to have relative path errors: the relative path will change due to the inclusion of the file (./
and ../): Below windows, each There are . and . folders under the folder.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What are the two types of article loading paths in PHP? What is the file path?. For more information, please follow other related articles on the PHP Chinese website!