Readfile function on a PHP 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
DavidSingleton
Forum Newbie
Posts: 2
Joined: Thu Oct 23, 2008 12:25 pm

Readfile function on a PHP file?

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Readfile function on a PHP file?

Post 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
DavidSingleton
Forum Newbie
Posts: 2
Joined: Thu Oct 23, 2008 12:25 pm

Re: Readfile function on a PHP file?

Post by DavidSingleton »

thanks!
Post Reply