Once you have created a script or an HTML content that you want to use in multiple pages is best stored in an external file and included in each
page you want to use it. This is accomplished with the include and require functions.
PHP has four commands that can be used to include code from an external file:
include('external_file.php');OR
require('external_file.php');
<?php include('C:/xampp/htdocs/includes/file.php'); // windows include('/usr/MAMP/htdocs/includes/file.php'); // unix (linux) ?>
<?php include('file.php'); // "file.php" is in the curent script directory include('../includes/file.php'); // "file.php" is in the "includes" folder, which is in the back directory ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Title page</title> <body> <?php include('templ/header.php'); ?> <div id="menu"> <?php include('templ/menu.php'); ?> </div> <div id="content">some content</div> </body> </html>With this method you can insert the same header and menu code in any PHP files in the Web site, all pages in the Web site can include the code of the header and menu files, and if you need to update the header or the menu later, you will only need to make changes in the "header.php" or "menu.php" file.
Using parentheses with the include commands is optional, the following would also work:
include 'includes/file.php';
include '/usr/MAMP/htdocs/includes/file.php';
When using a relative file path, you can use use "./" to indicate that the path begins in the current folder. Example:
include('./includes/file.php');
<table><tr> <th>Title 1</th> <th>Title 2</th> </tr></table>
.some_class { line-height: 150%; }
document.getElementById("id_button").onclick = function(){ window.open("http://coursesweb.net/"); }
$ar_dir = scandir("dir_name"); var_export($ar_dir);