HTML and CSS Reference
In-Depth Information
<link rel=”stylesheet” href=”site.css”>
This file includes all the tags for the start of my page, including links to external
JavaScript and CSS files. There's a PHP short tag in the title that prints out the value of
the $title variable. That enables you to use the header file for all of your pages and to
specify individual titles for each of them. To include this file, you use the following
$title = “Welcome!”;
include “header.php”;
Choosing Which Include Function to Use
Given these four very similar functions, how do you choose which makes the most sense
to use? The most important factor in making that decision is the content of the file to be
included. Generally, there are two types of include files: snippets of markup that will be
presented on your page, and PHP code libraries that provide code you are using on mul-
tiple pages throughout a site.
If the file you are including is a library, you just about always want to use require_once .
If you're using code from the library on a page, chances are the page will not work if the
library file is not available, meaning that you should use require rather than include . If
the file contains library code, you're not going to want to include it more than once. Let's
look at an example. You've written a library called temperature_converter.php . The
contents of the file are shown here:
function celsiusToFahrenheit($temp = 0) {
return round(($temp * 9/5) + 32);
This file contains one function, celsiusToFahrenheit() , which converts a Celsius tem-
perature to Fahrenheit and then rounds the result so that the function returns an integer.
Now let's look at a page that includes this file:
require_once “temperature_converter.php”;
Search WWH ::

Custom Search