php – 多个和标记
发布时间:2020-12-13 21:57:54 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试创建一个非常简单的Web应用程序,基本上是为了理解 HTML5,CSS和 JavaScript编码的最佳实践. 我的应用程序有3-4页,每个页面使用相同的菜单标题.因此,我希望通过将其写入单独的文件(PHP或HTML)来使其可重用. head.php(它可以重复使用): !DOCTYPE htm
我正在尝试创建一个非常简单的Web应用程序,基本上是为了理解
HTML5,CSS和
JavaScript编码的最佳实践.
我的应用程序有3-4页,每个页面使用相同的菜单标题.因此,我希望通过将其写入单独的文件(PHP或HTML)来使其可重用. head.php(它可以重复使用): <!DOCTYPE html> <html> <head> <link href="../../css/headermenu.css" rel="stylesheet" type="text/css"/> </head> <body> <ul id="menu"> <li><a href="#" class="home">Home<span></span></a></li> </ul> <p> </p> </body> </html> front.php: <?php include ("$_SERVER[DOCUMENT_ROOT]/page/common/head.php"); ?> HTML标记(脏代码): <!DOCTYPE html> <html> <head> <!DOCTYPE html> <html> <head> <link href="../../css/headermenu.css" rel="stylesheet" type="text/css"/> </head> <body> <ul id="menu"> <li><a href="#" class="home">Home<span></span></a></li> </ul> <p> </p> </body> </html></head> <body> <div> </div> <p> </p> </body> </html> 我有以下问题: > head.php有< body>和< head>标签.那么我应该在哪里编写这些PHP行来包含它? (在< head>或< body>)(我不希望在最后一页中有多个< head> s和< body> s) 我已经读过w3schools了. 解决方法
在我看来,阅读模板系统或了解框架/ CMS如何处理这个问题是个好主意.
按照自己的方式行事,你不能完全避免重复,例如关闭头标记< / head>在每个content.php中. 所以这只是一个想法: head.php <?php // Some other includes / requires,// code snippets... ?> <!DOCTYPE html> <html> <head> <!-- site-wide stylesheets --> <!-- & js-files --> <link href="css/main.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="my/global/scripts.js"></script> content.php <?php include ($_SERVER['DOCUMENT_ROOT'] . '/page/common/head.php'); ?> <!-- put page specific scripts & <!-- styles here --> <link href="my/pages/css/style.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="my/pages/js/scripts.js"></script> </head> <body> <div id="container"> <!-- content start --> <div id="content"> <h1>title</h1> <p>Your content</p> </div> <!-- end of content div --> <?php include ($_SERVER['DOCUMENT_ROOT'] . '/page/common/foot.php'); foot.php <div id="foot"> copyright etc </div> </div> <!-- end of container div --> </body> </html> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |