Home > Backend Development > PHP Tutorial > php 堂兄弟路径引用的话,怎么写简单点?

php 堂兄弟路径引用的话,怎么写简单点?

WBOY
Release: 2016-06-06 20:07:58
Original
866 people have browsed it

比如

<code>C:\AppServ\www\YB-PHP\PathDemo\China\ShanDong\LinYi\03.php</code>
Copy after login
Copy after login

要导入

<code>C:\AppServ\www\YB-PHP\PathDemo\China\JiangSu\NanJing\NanJingEcho.php</code>
Copy after login
Copy after login

就得写:

<code>include('../../JiangSu/NanJing/NanJingEcho.php');</code>
Copy after login
Copy after login

这样啰嗦不说,还老是容易弄错几个"../",每次我数这个,我都弄得好糊涂,怎么写简单点?

回复内容:

比如

<code>C:\AppServ\www\YB-PHP\PathDemo\China\ShanDong\LinYi\03.php</code>
Copy after login
Copy after login

要导入

<code>C:\AppServ\www\YB-PHP\PathDemo\China\JiangSu\NanJing\NanJingEcho.php</code>
Copy after login
Copy after login

就得写:

<code>include('../../JiangSu/NanJing/NanJingEcho.php');</code>
Copy after login
Copy after login

这样啰嗦不说,还老是容易弄错几个"../",每次我数这个,我都弄得好糊涂,怎么写简单点?

<code>define('BASEPATH', 'C:\AppServ\www\YB-PHP\PathDemo\China\');
include(BASEPATH . 'JiangSu/NanJing/NanJingEcho.php');</code>
Copy after login

psr4自动加载器

<code>$_SERVER['DOCUMENT_ROOT'].'/JiangSu/NanJing/NanJingEcho.php'
</code>
Copy after login
Related labels:
php
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