View Full Version : embeding a php file in a php file
Duffman
04-19-2006, 08:35 PM
so i have a php file called table.php that generates a table. i have another php file that the user actually goes to, index.php. what i want to do is have index.php make all the template crap, and i want to just put the table from table.php inside index.php. is this possible?
i was able to read table.php via the readfile function, but it doesn't execute it. i need a way to execute table.php, then display it within index.php
Have you tried include("file.php")
Duffman
04-19-2006, 09:07 PM
cool, thanks for the reply. that almost does what i want..
the way i'm making the site is to make an html file that has all kinds of places to fill in. for instance, in my html, i have ~content~ in the middle of it. then when someone goes to index.php, i use regular expressions to replace ~content~ with whatever i put in $content.
so my question now is... can i put that table.php into a variable, $content, so i can make it display correctly with my html?
EDIT: i just found a way to do it, but it requres a sub function:
function get_include_contents($filename) {
if (is_file($filename)) {
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
return false;
}
then:
$content = get_include_contents("table.php");
does anyone know a more graceful way of doing it?
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.