Page 1 of 1

Problem including a file

Posted: Wed May 01, 2002 6:49 pm
by hob_goblin
Alright, I have a tagboard, and right now im getting it onto my site through an iframe.

heres the code..

Code: Select all

<?
$content = <<<HTML
<iframe src=tfunc.php name=tagboard frameborder=0 height=400 width=100%></iframe>
HTML;
include('layout.php');
?>
and in layout.php i have a little section at the bottom that reads

Code: Select all

<div style="position:absolute;top:230;left:200">
<table cellpadding=0 cellspacing=0 border=1 bordercolor=black width=400>
<tr><td bordercolor=white><br><?=$content; ?></tr></td>
</table>
</div>
but if i try to make a file containing something like

Code: Select all

<?
$content = include('tfunc.php');;
include('layout.php');
?>
it ends up including the file at the top of the page..
here is an example of how it looks:
http://www.ice-on-fire.net/inclusion.php

any idea why it decided to put a 1 there and then include itself at the top of the page? or how i could edit inclusion.php to make it include in the right spot...

sorry, im only a couple weeks into learning php, (and im a teenager)

Posted: Wed May 01, 2002 10:47 pm
by mydimension

Code: Select all

$content = include('tfunc.php');
$content in this case will not contain the result of tfunc.php but rather the include function returns a TRUE or FALSE indicating the status of the include. the include file is executed immediately, not outputed to a variable.

Posted: Wed May 01, 2002 11:22 pm
by hob_goblin
ok thanks for explaining why it was up there,
any hints on how to fix it?

Posted: Thu May 02, 2002 8:11 am
by mydimension
is see two ways to do this:

1. inside tfunc.php, instead of printing the output you want, have it store it all into the $content variable.

2. don't include tfunc.php until you get to the point in the code where you want its contents to appear.

Posted: Thu May 02, 2002 8:41 am
by samscripts
or you could use output bufferingaround this bit:

Code: Select all

ob_start();

include('tfunc.php');

$content = ob_get_contents();
ob_end_clean();

// do whatever you want with $contents
sam