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

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

WBOY
WBOYOriginal
2016-06-06 20:07:58823browse

比如

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

要导入

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

就得写:

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

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

回复内容:

比如

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

要导入

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

就得写:

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

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

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

psr4自动加载器

<code>$_SERVER['DOCUMENT_ROOT'].'/JiangSu/NanJing/NanJingEcho.php'
</code>
Statement:
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