What are the two types of article loading paths in PHP? What is the file path?

慕斯
Release: 2023-03-10 15:42:02
Original
2582 people have browsed it

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 are the two types of article loading paths in PHP? What is the file path?

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(&#39;PI&#39;,3.14);
?>
Copy after login
<?php
//PHP文件加载路径
//相对路径加载
include_once &#39;include1.php&#39;;
echo $a ;
?>
Copy after login

The code demonstration results are as follows:

What are the two types of article loading paths in PHP? What is the file path?

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!