PHP包括页眉或页脚位置

I was hoping someone could help. I have just started to dabble with PHP includes for time saving in the future. For example I want to change the footer and header on a web page once (using include) instead of copying and pasting the code 30 or 40 times - oh no... a typo start again.

Which brings me to the question(s) where is it best to place this script?

<?php include("includes/headernav.html"); ?>

Can it be placed in a div, or should it be placed at the top of your code under the body?

If I want to make an image/banner include module. Can I

<?php include("includes/image.jpg"); ?> 

Or is best to wrap the image in html and apply like this?

<?php include("includes/imagewrapped.html"); ?>

Hope this helps:

<?php include("includes/ui_header.php"); ?>

My page content between header and footer

<?php include("includes/ui_footer.php"); ?>

You can probably save this as a function and call that function wherever you want to display.

It doesn't matter whether you put include in any place. However, it's better to put include in the top or bottom of your code

Do not include .jpeg files directly, use a wrapper. Only use include with other PHP files.

As for including the header, do it any way that feels natural as long as it produces valid html. There is no particular reason to declare another div element.

While including headers/footers/menus on the site, please keep in mind following things:

1) Your header/footer includes(blocks) should be wrapped inside a div.

2) This way then can be differentiated and any new change to them can be done easily.

3) Its always a good practice to include a wrapper div around an element as CSS can use it for styling.

4) Your header/footer includes (blocks) should have a flexibility that even we place them in header,footer or any sidebar, they should not disturb the UI.

1) Because you are including the HTML file, you probably need to include it where you want to display it.

2) Create a function in php where you send only image URL (maybe some other parameters) and function returns the HTML code (String) which you only echo on page where you want to display it. This way you can ensure, that all images will have the same code and styling.

for example

function generateImage($url=null) {
    if (isset($url)) return '<img src='.$url.' style="width: 100px; height:100px; border: 1px;" />';
    else return false;
}

The better way is to include always a php file.