php include 不同目錄
php include 不同目錄
01.情況
–index.php
———————————
<html>
<body>
<h1>歡迎訪問首頁</h1>
<p>一段文本。</p>
<p>一段文本。</p>
<?php
define(‘ROOT_PATH’,dirname(__FILE__));
echo ROOT_PATH;
echo ROOT_PATH.’/include/footer.php’;
include ROOT_PATH.’/include/footer.php’;
?>
</body>
</html>
–include/footer.php
———————————
<?php
echo “<p>Copyright c 2006-” . date(“Y”) . ” W3School.com.cn</p>”;
?>
==========
02.情況
–menu.php
<?php
echo ‘<a href=”/index.asp”>首頁</a> –
<a href=”/html/index.asp”>HTML 教程</a> –
<a href=”/css/index.asp”>CSS 教程</a> –
<a href=”/js/index.asp”>JavaScript 教程</a> –
<a href=”/php/index.asp”>PHP 教程</a>’;
?>
———————————
–include/index.php
<html>
<body>
<div class=”menu”>
<?php
define(‘ROOT_PATH’,dirname(dirname(__FILE__)));
echo ROOT_PATH.’/menu.php’;
include ROOT_PATH.’/menu.php’;
?>
</div>
<h1>歡迎來我的首頁</h1>
<p>Some text.</p>
<p>Some more text.</p>
</body>
</html>