[請益] include 的路徑順序
先說明檔案結構跟程式碼:
┬ a (目錄)
│├ a.php
│├ b.php
│└ c.php
├ c.php
└ s.php
s.php
<?php
include(a/a.php);
?>
c.php
<?php
echo '<div>this is c.php</div>';
?>
a/a.php
<?php
include('b.php');
include('c.php');
echo '<div>this is a/a.php</div>';
?>
a/b.php
<?php
echo '<div>this is a/b.php</div>';
?>
a/c.php
<?php
echo '<div>this is a/c.php</div>';
?>
接下來一樣是執行 s.php
狀況 1: c.php 存在,會產生這樣的結果:
this is a/b.php
this is c.php
this is a/a.php
狀況 2: c.php 不存在,會產生這樣的結果:
this is a/b.php
this is a/c.php
this is a/a.php
狀況 3: c.php 存在,把 a/a.php 改成
<?php
include('./b.php');
include('./c.php');
echo '<div>this is a/a.php</div>';
?>
會出現以下的結果:
xxxx
xxxx ←前兩行是找不到 b.php 的 warning 訊息
this is c.php
this is a/a.php
如果要用相對路徑,想請問 include 的路徑是怎麼判定的?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.62.109.197
推
06/23 20:51, , 1F
06/23 20:51, 1F
推
06/23 20:55, , 2F
06/23 20:55, 2F
推
06/23 23:58, , 3F
06/23 23:58, 3F
推
06/24 00:01, , 4F
06/24 00:01, 4F
→
06/24 00:01, , 5F
06/24 00:01, 5F
推
06/24 02:20, , 6F
06/24 02:20, 6F
推
06/24 09:04, , 7F
06/24 09:04, 7F
推
06/24 11:55, , 8F
06/24 11:55, 8F
→
06/24 11:56, , 9F
06/24 11:56, 9F
→
06/24 11:56, , 10F
06/24 11:56, 10F
→
06/24 11:56, , 11F
06/24 11:56, 11F
→
06/24 11:57, , 12F
06/24 11:57, 12F
→
06/24 11:58, , 13F
06/24 11:58, 13F
→
06/24 11:58, , 14F
06/24 11:58, 14F
→
06/24 11:59, , 15F
06/24 11:59, 15F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章