Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using PHP as an include within a PHP page? 1

Status
Not open for further replies.

Julianne

Technical User
Jan 30, 2002
156
GB
Is it possible to use PHP code as an include within another PHP page? I know how to do it when the include is just plain HTML (strip out head/body tags etc) but I've never done it with PHP code. I don't know what I should be doing because there's a load of PHP before the head tags etc. Should I be stripping some of that?

If anyone can explain what I need to take out/leave in I'd be grateful - many thanks.

Visit my ice hockey site at:
 
I did that already and the whole page got screwed up. Do I leave all the PHP in place and still strip out the <head> and <body> tags or do I have to remove certain PHP lines too?

Visit my ice hockey site at:
 
Only you can answer that. Of all of us, only you can see your code.

Imagine that you have taken the included file and dumped it verbatim into the running script file at the point where the include() invocation appears. For all intents and purposes, that's what happens.

The only difference is that when a file is included, PHP drops from execution mode (what happens between <?php...?> tags) into throughput mode. Unless the included file has <?php...?> tags, the text of the included file will just be passed through to the browser.

What will happen to your script were you to dump the included script directly into the running script using a text-editor?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I'm not recommending at all that you typographically include the file. In fact, in most situations, the exact opposite is the way to go.

The advantage to including files is that you can have one piece of code to maintain that can be used in multiple scripts. Typically, if a set of scripts are going to output common HTML-page headers or footers, that HTML is placed in a file that is included everywhere.

Also, class definitions, function definitions, and configuration options be in include files.

The salient feature of include files is: is the piece of code going to be used, as is, by multiple scripts. If so, put it in an include file.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
sleipnir214,

I don't know if it was clear to everyone but your first post was clear to me. And although I already understood that, I've never seen it described quite that way.

I gave you a

* S * T * A * R *

tgus

____________________________
Families can be together forever...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top