[PHP] include-ing results in variable?

2001-10-27 Thread Nathaniel Merriam

This is what I'm trying to do, and I think I'm just missing some logic in
how to think like PHP.

I have a global included file (global.inc) where I set up variables, open
the database, etc, and I include it in the header of every HTML file on the
site.

One thing I would like to set as a variable is the result of php code in
another file (banner.inc) -- this result is pulled up several times per
page, and it seems that it would be more efficient to have it processed
once, and then just plug that result into a variable which I can call every
time I need that result data.

The problem is that it spits out the result as soon as the variable is set!
So at the top of every page, it just prints out all the data results
immediately rather than waiting for me to echo or print the variable.

I have this at the top of the page:

?php
$banner = include (banner.inc);
?
(which immediately spits out the result of the include!)

But I want to print the results several times a page with this:
?=$banner?

I feel certain I'm missing something obvious, but haven't been able to
clarify it in my head despite google searching and browsing through a couple
of books.

thanks for any help!
Nathaniel



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: include-ing results in variable?

2001-10-27 Thread Nathaniel Merriam

Thanks for your help, I've got it working now (I think!). You're right, I
had an echo at the bottom of the included script and I think was loathe to
mess with it since I spent about 12 hours getting that one to work!

I had read the man page for include -- even the example with the return! --
about a hundred times today, but it just didn't make sense in my head even
though I suspected it was related to my problem. This is my first foray into
any kind of programming since I played with Turbo Pascal about 10 years ago,
so I'm fumbling around a bit :)

thanks again,
nathaniel


 What's in banner.inc?  Because, as noted in the manual, an included file
 can have a return value *if you give it one*.  If you have code there
 that's echoing/printing, that will indeed spit out immediately.  The trick
 is to instead capture that output into a variable and return it.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]