簡體   English   中英

PHP包含和html標簽

[英]Php includes and html tags

我有一個正在構建的網站,並且計划將php inlude用於頁眉和頁腳。

可以說標題是<html>.....</html

頁腳是<html>......</html>

同一頁面上的html標記的開頭和結尾會怎樣?

會有問題嗎?

同一頁上可以有兩個打開標簽和結束標簽嗎?

header

footer

如果要在頁面上使用“ include”,“ require”或“ require_once” ...,則所包含的文件包含有效的標記。 包含文件視為通常在<body></body>標記之間編寫的內容。

例:

的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文件

<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

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

請注意,在header.php和footer.php文件中,以下幾行已被刪除...

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

</body>
</html>

現代的“智能”瀏覽器通常會忽略多個<head><html><body>標簽。 他們只會根據瀏覽器“想”要寫的內容來“為您重寫代碼”。 但是會正確嗎?

不要依靠瀏覽器“修復”您的錯誤。 編寫良好,干凈,有效的代碼。

編碼愉快!

您的包含header應以

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

footer應該以

</html>

這是一個小的html頁面結構的示例

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

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

</body>
</html> 

示例說明:

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

我的問題是由於php include而在頁面上有多個開始和結束標簽

一個HTML文檔只能有一個 html標記。 如果僅將多個HTML放在一起,則它將是無效的文檔,並且瀏覽器可能無法顯示它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM