[Techtalk] simple php question
Terri Oda
terri at zone12.com
Mon Mar 18 14:42:29 EST 2002
(Sorry if someone's already said this -- I'm queueing this message up, but
it won't get sent 'till later tonight, possibly after someone else has said
exactly what I'm saying!)
At 02:14 AM 17/03/02 -0500, Davis, Jennifer wrote:
>Another quickie question. Is there a quick way with php to import some code
>from one html file to another. Basically I want to write a menu bar that
>will appear on all pages of a site.
There's two functions for that,
<?php include("myfile.html"); ?>
and
<?php require("myfile.html"); ?>
The first just includes the file when it gets to that line of code. If the
file can't be found or opened for some reason, it simply doesn't get
included. I can't remember if it automatically prints an error message or
if you have to make one yourself.
The second one will die with an error if the file can't be opened, and it
will do this *before* loading the rest of the file, so you'll get only the
error, not a half-completed page, if the required file can't be
included. Because this check is done first, before parsing the rest of the
document, require() means the file has to exist for the php document to
work at all (even if require() is in an if statement and may not actually
be used in some cases).
Which one you use depends pretty much on what behaviour you want.
Terri
More information about the Techtalk
mailing list