如何使用PHP中的“include”
“include”的用法
为了备忘录而做记事。
将在每个文件中重复使用的部分写入base.php文件中。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title><?php echo $title ;?></title>
</head>
<body>
<div class="container">
<?php include $content; ?>
</div>
</body>
在标题部分使用”$title”,在正文部分使用”$content”,并且可以将其替换为调用者变量。
当要从index.php文件中加载base.php时,可以使用include。
<?php
$title = 'HogeeeWorld!!';
$content = __DIR__ . '/content.php';
include 'base.php';
$content的内容是从以下文件中读取的。
<h1>本文だよ!!</h1>
