Pavlos1316
Pavlos1316

Reputation: 444

HTML structure?

I think this one is simple just explain it a bit please...

Supose I have this index.php (Don't look for script errors)

<html>
<head>
</head>
<body>
require(home.php)
</body>
</html>

And my home.php (I saw this somewhere and I am wondering, even if it is working is it wrong?) Instead of having again the normal html structure as above, you have:

<body>
some code
</body>

LEAVING OUT all the other tags.

Is this correct? Yes? No? Why?

Thank you

Edit: What if I am calling a js script in my head tag? Would the home.php inherite it?

Upvotes: 0

Views: 198

Answers (7)

Frog
Frog

Reputation: 1641

No, this is not correct, there are quite a bit of errors, but it won't work because of the following reasons:

  1. You don't open/close PHP using the <?php and ?> tags. This way require() just won't execute;
  2. Require() needs quotes (since it's argument should be a string), so require('home.php'); is correct;
  3. As I already changed in point 2: you have to end every argument with a semicolon (;);
  4. You should probably replace the <body></body> tags in home.php with <?php ?> tags, so that Google can't index that page (and can only do it from index.php;

Apart from that you also have these markup errors:

  1. Always use a Doctype. Otherwise your HTML won't validate;
  2. The <title></title> tag is mandatory;

Hope this helps.

Upvotes: 1

sll
sll

Reputation: 62484

Let's main page to provide other pages by <BODY> tag

Upvotes: 0

tehvan
tehvan

Reputation: 10369

Drop the start and end tag in home.php and it'll be ok (check http://www.php.net/manual/en/function.include.php for more information if needed)

Upvotes: 0

benhowdle89
benhowdle89

Reputation: 37454

Re-iterating what others are saying. It would look and behave the same (most likely), but fails semantically.

That is all.

Upvotes: 0

Quentin
Quentin

Reputation: 943100

It is incorrect. For every version of HTML, the body element may only be a child of the html element. It may never be a child of another body element.

Upvotes: 2

user827080
user827080

Reputation:

Yes. You are including the file, so php is litterally "putting it in between there".

BTW: you now have double body tags.

Upvotes: 0

Mild Fuzz
Mild Fuzz

Reputation: 30651

It probably shouldn't have the <body> tag again, but otherwise okay.

Upvotes: 2

Related Questions