javascript - Multiple <HTML> tags in a single page - Stack Overflow

I am fairly new to PHP. I have been developing a PHP website code which requires a mon header (header.p

I am fairly new to PHP. I have been developing a PHP website code which requires a mon header (header.php). I have included mon header.php page in content.php. Now I see 2 2 and 2 tags in the HTML view source.

Code is something like this -

<?php
      include "header.php";

      //some php code.
?>
<html>
<head> <script src="test.js"> </script></head>
   <body>
        <h1> Test Page </h1>
   </body>
</html>

In page source, my code looks like this,

<html>
<head> <script src="header.js"> </script></head>
   <body>
        <h1> Menu Page </h1>
   </body>
</html>
<html>
<head> <script src="test.js"> </script></head>
   <body>
        <h1> Test Page </h1>
   </body>
</html>

Please suggest if this code is OK or multiple html or head tags are not good for SEO and/or performance. Also please suggest workaround.

I am fairly new to PHP. I have been developing a PHP website code which requires a mon header (header.php). I have included mon header.php page in content.php. Now I see 2 2 and 2 tags in the HTML view source.

Code is something like this -

<?php
      include "header.php";

      //some php code.
?>
<html>
<head> <script src="test.js"> </script></head>
   <body>
        <h1> Test Page </h1>
   </body>
</html>

In page source, my code looks like this,

<html>
<head> <script src="header.js"> </script></head>
   <body>
        <h1> Menu Page </h1>
   </body>
</html>
<html>
<head> <script src="test.js"> </script></head>
   <body>
        <h1> Test Page </h1>
   </body>
</html>

Please suggest if this code is OK or multiple html or head tags are not good for SEO and/or performance. Also please suggest workaround.

Share Improve this question asked Jul 11, 2014 at 21:50 user20072008user20072008 3798 silver badges24 bronze badges 7
  • 2 Not OK. Only one <html> tag per document. – Pointy Commented Jul 11, 2014 at 21:51
  • 1 Your HTML structure is broken. The browsers might be forgiving but the results will be unpredictable. – user1864610 Commented Jul 11, 2014 at 21:52
  • 1 The work-around is for you to determine what in your PHP code is breaking your html and fix it. – scrappedcola Commented Jul 11, 2014 at 21:54
  • 2 Change the header.php file so it won't output any tags except maybe the head tag and it's contents. – HaukurHaf Commented Jul 11, 2014 at 21:56
  • 1 @jasper, What can be done is use header.php as what it sounds like, a header. Put the header stuff like the <HTML> tag and JS/CSS references only in there. – developerwjk Commented Jul 11, 2014 at 21:57
 |  Show 2 more ments

7 Answers 7

Reset to default 2

No, you can have only one <HTML> per page.

What you are looking for is a "layout pattern".

<!DOCTYPE HTML>
<HTML>

    <HEAD>
        <!-- your link to stylesheet, jquery etc -->
    </HEAD>

    <BODY>
        <!-- here include your header -->

        <!-- and your content -->
    </BODY>

</HTML>

Both header and content don't have any <HTML> or the rest of it - it's just <DIV>'s etc.

If you are struggling with the basic HTML format, here are some basic html templates you can use.


For any bigger application, it makes sense to use a framework (such as Laravel) and some templating engine.

However, for this simple example, you could have something like this:

[file index.php]
- resolve what content to show based on $_GET
- include layout, tell it what title and content to show

[layout]
as shown above, add into <head> a <title> tag
in body, include the content files

[additional files for content, header etc]
...

A Html document contains exactly 1 HTML tag with a head and body tag inside it, by definition. So your code is not valid HTML.

No. You can only have one set of

<html> </html>

tags

I think this is what you are looking for:

your header.php should contain the following html ONLY

<html>
   <head>
     <title></title>
     ....
   </head>
   <body>

Now your body page should contain only divs and content that goes within <body></body> only.

Then you have footer.php that ends the html like this:

   </body>
</html>

so in your main body file you would have the following:

<?php
   include "header.php";

   //some php code.
?>

<h1> Test Page </h1>

<?php
   include "footer.php";
?>

You should use only one <html><head><body> and <h1> Tag to write valid html-code.

If you try to build a template like engine with php you could build it like that:

header.php

<!DOCTYPE HTML>
<html>
<head>
    <script src="my.js"></script>
</head>
<body>

index.php

<?php
     include_once("header.php");
?>
<h1><?php echo $page_title; ?></h1>

<div class="main">
    <p>This is my Content</p>
</div>

<?php
    include_once("footer.php");
?>

footer.php

<script src="additional.js"></script>
</body>
</html>

You need to delete html and body tag etc in header.php. That will solve your problem

It turns out that there are sometimes ment lines at the top of a html file that are used to configure the html for different browsers. If you run a script to strip the ment of something like this:

<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>  <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-GB"> <!--<![endif]-->

you will inadvertently end up with the appearance of 4 html loops which then causes a parser such as beautifulsoup to fail badly.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742419197a4440340.html

相关推荐

  • javascript - Multiple &lt;HTML&gt; tags in a single page - Stack Overflow

    I am fairly new to PHP. I have been developing a PHP website code which requires a mon header (header.p

    22小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信