The code itself is very simple. It uses the structure of language "include". It may not take parentheses. This structure will allow you to include a PHP file to interpret. Here is an example to include the "haut.php" in the file:
PHP Code:
<?php
include 'haut.php' ;
?>
The principle is simple: you can go through the code execute PHP code included in "haut.php. This means that if for example the included file contains HTML code or instructions "echo" displaying HTML, you can display a well-defined HTML code on all pages of your sites through a single file that you include when and wherever you want.
Now a practical example that will include a PHP page, the top of the site. All of our PHP pages can be reused so that the top site is the same on all pages. For this example we'll use two files, one will be HTML (the "haut.php") and will be the same on all pages for which we will call him, and one in PHP will include this file.
File Contents "haut.php":
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns= "http://www.w3.org/1999/xhtml" xml:lang= "en" lang= "en" >
<head>
<title> Welcome to my website! </ title>
</ head>
<body>
<h1> Welcome to my site! </ h1>
File Contents "bas.php" which will be the footer of the site:
</body>
</html>
Contents of the file "index.php" to be the home:
<? php
include 'haut.php';
echo 'Here the content of the site';
include 'bas.php';
?>
Giving in HTML when you call the page "index.php"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns= "http://www.w3.org/1999/xhtml" xml:lang= "en" lang= "en" >
<head>
<title> Welcome to my website! </ title>
</ head>
<body>
<h1> Welcome to my site! </ h1>
Here the content of the site
</body>
</html>
Attention to the use abundance files included. Include the more you use, the more time to generate the page will be slow (because it is necessary to make a disk access to read the files). Prefer to include one of a file a little larger than 4 files very small.
Bookmarks