Problem including a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Problem including a file

Post 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)
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

ok thanks for explaining why it was up there,
any hints on how to fix it?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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.
samscripts
Forum Commoner
Posts: 57
Joined: Tue Apr 23, 2002 4:34 pm
Location: London, UK

Post 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
Post Reply