简体   繁体   English

PHP包含和html标签

[英]Php includes and html tags

I have a website that I am building and I am planning to use php inlude for the header and footer. 我有一个正在构建的网站,并且计划将php inlude用于页眉和页脚。

Lets say the header is <html>.....</html 可以说标题是<html>.....</html

Footer is <html>......</html> 页脚是<html>......</html>

What happens with the beginning and ending of html tags on the same page? 同一页面上的html标记的开头和结尾会怎样?

Is there gonna be a problem? 会有问题吗?

Can there be two open and end tags on the same page? 同一页上可以有两个打开标签和结束标签吗?

header

footer

If you are going to use "include", "require" or "require_once" on your page... the included file should contain ONLY valid markup. 如果要在页面上使用“ include”,“ require”或“ require_once” ...,则所包含的文件包含有效的标记。 Think of your include files as what you would normally write between the <body> and </body> tags. 包含文件视为通常在<body></body>标记之间编写的内容。

EXAMPLE: 例:

index.php 的index.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php require'includes/header.php' ?>

my body content goes here

<?php require'includes/footer.php' ?>
</body>
</html>

header.php header.php文件

<div id="header">
<div><img src="/where/my/image/is/filename.jpg" alt="my header image" title="my image title" /></div>
<div id="menu">this is where I will put my menu</div>
</div>

footer.php footer.php

<div id="footer">this is where I will put my footer content</div>

Notice that in the header.php and footer.php files the following lines have been removed... 请注意,在header.php和footer.php文件中,以下几行已被删除...

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>

</body>
</html>

Multiple <head> , <html> , <body> tags are generally ignored by modern "smart" browsers. 现代的“智能”浏览器通常会忽略多个<head><html><body>标签。 They will just "rewrite your code for you" based on what the browser "thinks" you meant to write. 他们只会根据浏览器“想”要写的内容来“为您重写代码”。 BUT will it be correct!? 但是会正确吗?

Do not rely on browsers to "fix" your mistakes. 不要依靠浏览器“修复”您的错误。 Write good, clean, valid code. 编写良好,干净,有效的代码。

Happy Coding ! 编码愉快!

Your include header should start with 您的包含header应以

<!DOCTYPE html>
<html>
<head>
some meta tags, css and js
</head>

And you footer should end with footer应该以

</html>

Here's an example of a small html page structure 这是一个小的html页面结构的示例

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html> 

Example Explanation: 示例说明:

The `DOCTYPE` declaration defines the document type to be HTML
The text between `<html>` and `</html>` describes an HTML document
The text between `<head>` and `</head>` provides information about the document
The text between `<title>` and `</title>` provides a title for the document
The text between `<body>` and `</body>` describes the visible page content
The text between `<h1>` and `</h1>` describes a heading
The text between `<p>` and `</p>` describes a paragraph

UPDATE UPDATE

My questions is about having multiple opening and ending tags on a page because of php include 我的问题是由于php include而在页面上有多个开始和结束标签

An HTML document can only have ONE html tag. 一个HTML文档只能有一个 html标记。 If you just put several HTML together, it will be an invalid document, and the browsers may have problems displaying it. 如果仅将多个HTML放在一起,则它将是无效的文档,并且浏览器可能无法显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM