Dre_Dre
Dre_Dre

Reputation: 765

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.

Lets say the header is <html>.....</html

Footer is <html>......</html>

What happens with the beginning and ending of html tags on the same page?

Is there gonna be a problem?

Can there be two open and end tags on the same page?

header

footer

Upvotes: 2

Views: 183

Answers (2)

Kuya
Kuya

Reputation: 7310

If you are going to use "include", "require" or "require_once" on your page... the included file should contain ONLY valid markup. Think of your include files as what you would normally write between the <body> and </body> tags.

EXAMPLE:

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>

Notice that in the header.php and footer.php files the following lines have been removed...

<!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. 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.

Upvotes: 3

Pedro Lobito
Pedro Lobito

Reputation: 99081

Your include header should start with

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

And you footer should end with

</html>

Here's an example of a small html page structure

<!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

My questions is about having multiple opening and ending tags on a page because of php include

An HTML document can only have ONE html tag. If you just put several HTML together, it will be an invalid document, and the browsers may have problems displaying it.

Upvotes: 0

Related Questions