The most prevalent means for ensuring such is by isolating functional
CHAPTER 3 ?– PHP BASICS 109
components into separate files and then reassembling those files as needed. PHP
offers four statements for including such files into applications, each of which is
introduced in this section.
The include() Statement
The include() statement will evaluate and include a file into the location where it is
called. Including a file produces the same result as copying the data from the file
specified into the location in which the statement appears. Its prototype follows:
include(/path/to/filename)
Like the print and echo statements, you have the option of omitting the parentheses
when using include(). For example, if you want to include a series of predefined
functions and configuration variables, you could place them into a separate file
(called init.inc.php, for example), and then include that file within the top of each
PHP script, like this:
include "/usr/local/lib/php/wjgilmore/init.inc.php";
/* the script continues here */
?>
You can also execute include() statements conditionally. For example, if an
include() statement is placed in an if statement, the file will be included only if the
if statement in which it is enclosed evaluates to true. One quirk regarding the use of
include() in a conditional is that it must be enclosed in statement block curly brackets
or in the alternative statement enclosure.
Pages:
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193