Re: include-ing results in variable?
| From: | CC Zona | Date: | Sat, 27 Oct 2001 23:35:50 +0000 |
| Subject: | Re: include-ing results in variable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-72594@lists.php.net to get a copy of this message | ||
In article <20011027215131.91029.qmail@pb1.pair.com>,
asdasd@dsdad.com (Nathaniel Merriam) wrote:
> 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?>
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.
//"simpleinclude.inc"
<?php
$ret=somefunct("foo");
$ret.=anotherfunct("bar");
return $ret;
?>
//"otherpage.php"
<?php
$banner=include("simpleinclude.inc");
...
echo $banner;
?>
--
CC