[轉貼]PHP: 完美實現ASP.NET MasterPage的方法
<body>
<div><?php include('menu.php');?></div>
<div><?php include($page_content);?></div>
<div><?php include('footer.php');?></div>
</body>
<?php
define('app_root',$_SERVER['DOCUMENT_ROOT']);
require_once(app_root."/shared/opendb.inc");
?>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title><?php echo $pagetitle ?></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="./style/globalreset.css" rel="stylesheet" media="screen" type="text/css" />
<link href="./style/layout.css" rel="stylesheet" media="screen" type="text/css" />
</head>
<body>
<div id="page">
<div id="header">
<div id="title">
<h1><a href="./index.php"><img src='./images/logo_full.jpg' height='50' /></a></h1>
</div>
<div id="cart">
<?php //require_once(app_root."/shared/login.inc"); ?>
</div>
</div>
<div id="wrapper">
<div id="sidebar">
<div id="menubox">
<?php //require_once(app_root."/shared/navigation.inc"); ?>
</div>
</div>
<div id="mainbox">
<div id="mainarea">
<?php echo $pagemaincontent; ?>
</div>
</div>
</div>
<div id="footer">
</div>
</div>
</body>
</html>
<?php
define('app_root',$_SERVER['DOCUMENT_ROOT']);
require_once(app_root."/shared/opendb.inc");
$pagetitle = "頁面標題";
//將整個頁面輸出放到緩衝區
ob_start();
?>
頁面內容,隨便你輸出
<?php
//將緩衝區的內容放到變數裏面,然後清除緩衝區
$pagemaincontent = ob_get_contents();
ob_end_clean();
//套用主板頁面
include(app_root."/shared/master.php");
?>