[thelist] A tip with PHP

Seb seb at members.evolt.org
Tue Jul 17 11:02:49 CDT 2001


> > Although I've got a question :
> >
> > > $page = join ('', file ($fichier));
> > >
> > > echo $page;
> >
> > Why not use something like :
> > include($fichier);
> >
> > What do you think, people?
>
> I think that:
> "The include() statement includes and evaluates the specified file."
>
> That is not what I want to do, I want the content of a file to be placed
in
> my variable $page. Then, only after, display it. (you could perform some
> "search and replace" before echoing the page)
>
> 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..
>
> The only shorter option I see in my case is:
> echo join ('', file ($fichier));

You're actually wasting resources by indirectly assigning the contents of a
file into another variable. I'd personally go down the include route every
time.

eg:

<? $fichier = $whatever;
include($fichier); ?>

When you include a file, it only evaluates what's inside PHP delimiter tags,
so if you leave them out it treats your included file as HTML to be output.

I do this as the basis of the content display system on sebpotter.org, it
makes life so much easier editing HTML fragments in discrete files instead
of db fields.

Seb
http://www.sebpotter.org






More information about the thelist mailing list