Page 1 of 1

Readfile function on a PHP file?

Posted: Tue Oct 28, 2008 11:26 am
by DavidSingleton
I'm having some problems, wondering if any of you could help me out. I've been searching the internet for hours trying to figure this out, so I'll put it to people with much more PHP knowledge than myself.

I have a class that creates a spry based tab set for users. The class itself takes builds html which i then echo out. The problem i'm having is one of my class variables is a filename (specifically, the file you want said tab to display) This file could (and probably will) be php with dynamic content. I need to do something along the lines of a readfile where the server processes the page and just returns me the results to display in the tab. Can someone help. Here is my class.

Code: Select all

 
class Tabs  {
    #All these variables should be arrays with the same ammount of values
    public $NameTabs;
    public $TabFiles;
    
    public function __construct($NameTabs, $TabFiles)   {
        $this->NameTabs = $NameTabs;
        $this->TabFiles = $TabFiles;
    }
    
    public function ReturnTabs()    {
        $Tab = '<div id="TabbedPanels" class="TabbedPanels">';
        $Tab .= '<ul class="TabbedPanelsTabGroup">';
        $i = 0;
        foreach($this->NameTab as $NT)  {
            $Tab .= '<li class="TabbedPanelsTab" tabindex="' . $i . '">' . $NT . '</li>';
            $i++;
        }
        $Tab .= "</ul>";
        $Tab .= '<div class="TabbedPanelsContentGroup">';
        $i = 0;
        foreach($this->TabFiles as $TF) {
            $Tab .= '<div class="TabbedPanelsContent" id="TB' . $i . '">';
            $Tab .= readfile($TF); //THIS IS THE LINE THAT KEEPS HOSING ME
            $Tab .= "</div>";
            $i++;           
        }
        $Tab .= "</div>";
        $Tab .= "</div>";
        $Tab .= '<script type="text/javascript">';
        $Tab .= "var TabbedPanels1 = new Spry.Widget.TabbedPanels('TabbedPanels');";
        $Tab .= "</script>";
        return $Tab;
    }
    
    
}
 
Any help is greatly appreciated.

Re: Readfile function on a PHP file?

Posted: Tue Oct 28, 2008 1:48 pm
by requinix
Use output buffering.

Code: Select all

ob_start();
include $php_file;
$output = ob_get_contents();
ob_end_clean();
 
// $output is whatever the PHP file tried to print

Re: Readfile function on a PHP file?

Posted: Tue Oct 28, 2008 1:50 pm
by DavidSingleton
thanks!