# 1.整理文件头部 我们看到文件头部内容重复所以创建data_v3/v2/templates/title.php ~~~ <h1>标题</h1> <p>这是引进的头部内容(require)</p> ~~~ # 2.修改data_v3/v2/index.php ~~~ ............... ............... <!DOCTYPE html> <html> <head> <title>我的博客</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> </head> <body> <?php require 'templates/title.php' ?> <?php while ($row = $stmt->fetch(PDO::FETCH_ASSOC)): ?> <h2> <?php echo htmlspecialchars($row['title'], ENT_HTML5, 'UTF-8') ?> </h2> ............... ............... ~~~ # 3.修改data_v3/v2/view-post.php ~~~ ............... ............... <!DOCTYPE html> <html> <head> <title> 我的博客 | <?php echo htmlspecialchars($row['title'], ENT_HTML5, 'UTF-8') ?> </title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> </head> <body> <?php require 'templates/title.php' ?> <h2> <?php echo htmlspecialchars($row['title'], ENT_HTML5, 'UTF-8') ?> </h2> ............... ............... ~~~