[thelist] A tip with PHP

Ray Hill lists at prydain.com
Tue Jul 17 10:53:21 CDT 2001


> If you do include, obviously you gonna get errors, since
> the included file must be specialy tailored for your
> purpose, that is beginning by ?> and eventually finishing
> by <?php in order for the html to be displayed correctly..

No, it's actually easier than that.  When you include a file it does
evaluate the contents, but it starts in HTML mode within each new
file.  So if your include file just contains HTML, it simply prints it
to the screen.  It's when your include file includes PHP that you'll
have to add the <? ?> tags.

This is actually how my prydain.com site rund (except it gets the
include value from the $page in the query string instead of at
random), so I know it works, and *does* save a lot of maintenance
time.  Especially since having the content in its own file allows for
the look/feel to all be generated by a single layout file that's also
included, as such:

1) index.php in any folder sets the $section and $root variables
($root being the "../../" path back to the root folder), and then
includes $root . "layout.php".

2) layout.php draws all of the look/feel tables, including a sidebar
or footer file when needed.  Between the $section that's set in the
index file and the $page that's optionally set in the query string,
you've got plenty of info to customize your navigation bar.

3) In the proper place in the table structure, $layout checks to see
if $root . $section . "/" . $page . ".php" exists, including it if it
does and printing an error to the content area if it does not.

I know that's not exactly what you were looking for, but I figured it
might be worth mentioning another way that this trick can be used.


--ray






More information about the thelist mailing list