|
Using PHP
All PHP commands are written in the form of <? code ?> or <?PHP code
PHP?> and placed inside a standard HTML document with an extension of .php on the
CGI-BIN server. Entire blocks of PHP code can be placed between these special tags.
Depending on how your own computer is set up, PHP files may cause problems. If another
program on your system uses .php as an extension to a particular file type, PHP files may
be opened by that program.
Another possible problem is that your HTML editor and browser might not know what to do with PHP
tags and/or .php files. The reason for this is that you probably don't have the PHP
pre-processor on your system.
There are various versions of PHP available to install on home systems, but I cannot advise you
on how to go about doing so - particularly if your system is not set up as a server.
Including a file
The command to do this can be used in two ways - with a literal or variable filename.
include("file.txt");
This would include the contents of the file called file.txt at the point in the
document where the code was placed. The full path to the file must be given.
include($filename);
This would include the contents of the file which had its name and path stored in a variable
called $filename - a much more flexible way of referencing it. The variable would
have to be defined elsewhere, possibly using a command such as $filename = "file.txt";
It would also be possible to store variables like that in a MySQL database if your site is
extremely large.
If the file you are including contains HTML, it is still wise to name it with a .txt
extension. The reason being that it is not a complete HTML document, and should not be named
as if it were.
Files containing additional PHP code can be included and they will also be processed by the PHP
engine - if they have a .php extension that is.
|