Jump to content

body tags and php includes


real_illusions

Recommended Posts

this is possibly a more html question than a php question...anywayyou got your basic page<html><head></head><body></body></html>if you have the <body> tag in a php include file, would that affect the page in anyway?when the browser reads the file on the server, the server will include whatever html is in that php include file, and it will just display as normal html in the source code.i know in the past, i've made the mistake of having body tags in the include file, and so i had several body tags in the source code.so, leaving it out and putting in the include file, i would of thought would have no affect on the page.reason been is, i have a few preloaded images for a rollover menu in javascript, on every page, and if i change the images, i have to edit the body tag on every page. and editing 1 page is alot easier than editing alot more :):)

Link to comment
Share on other sites

it will not be valid HTML...whether or not it renders differently is a browser to browser issue...it depends on how standards compliant they are....IE would probably have little or no difference and FF would probably give your code 40 lashings for such a thing :)When using includes pretend that the code in the include file was actually being written in the spot you are includeing it (because basically that is what includes are).Hope this helps

Link to comment
Share on other sites

ahh..okwell..the first body tag will be in the menu include.and the closing body tag as normal in the code.

why not do thismain page
<html><head>...</head><body><div>Header</div><div><?php include('menu.html');?></div><div>some more code...</div></body></html>

menu.html

<ul><li><a href="somepage.html">some link</a></li><li><a href="somepage.html">some link</a></li><li><a href="somepage.html">some link</a></li><li><a href="somepage.html">some link</a></li><li><a href="somepage.html">some link</a></li></ul><!--or what ever-->

The includes do not have ot contain all the html tags of a normal page becuase they are not they are just pieces of a page that you want ot reused easily.There is no need to put in an extra set of body tags.

Link to comment
Share on other sites

thats pretty much the set up i have at the momentjust wondered if it was possible to put the body tag in the php include without causing the page to self destruct.there'll still be only the one body tag though in the source code

Link to comment
Share on other sites

But the include file and all its code is a part of the main source code when the page finishes rendering. So yes the page will probably self destruct...lolTake a look at the browser source one the page has loaded :)

Link to comment
Share on other sites

well..tested it out and it didn't blow up or do anything weird that i could see like cause the computer to grow legs and run off down the streetseemed to work ok in both firefox and explorerhttp://www.midlandkarting.co.ukthe main index page hasn't got the include, but the rest of the pages have

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...