Jump to content


Photo

using output-control functions to capture output from eval()


  • Please log in to reply
1 reply to this topic

#1 Sasuun

Sasuun
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 March 2006 - 06:57 PM

I'm using eval to execute php I have stored in a mysql database for a blocks system, but in order to aviod any problems using function such as header() or session_start() after output has been sent, I store all of my output in a variable $OUTPUT and on the last line of my script echo that var.

This was all going fine until I added a php filter to my block system, which worked great, except my output would always be printed above everything else on my site, so I went to php.net and read up on the eval() function, and lo and behold I finally realized they had a tip for using eval
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Tip: As with anything that outputs its result directly to the browser, you can use the output-control functions to capture the output of this function, and save it in a string (for example).[/quote]

I have no idea how to use output-control functions, and I've been reading about them searching for a couple of hours with no luck Does anyone know how I could capture the output and put it in my $OUTPUT var?

incase it helps, here is my get_blocks function
function get_blocks($position)
    {
        $ACHTML = '';
        #initialize variable and make sure it doesn't have any data in it
        $sql = "SELECT * FROM ac_blocks WHERE `position` = '$position' ORDER BY `order` ASC";
        $get = mysql_query($sql)
                or die(mysql_error());
                while ($blocks = mysql_fetch_array($get))
                {
                    if ($position == "C")
                    {
                        $ACHTML .= site_box($blocks['block_title']);
                    }else 
                    {
                        $ACHTML .= make_menu($blocks['block_title']);
                    }
                    if ($blocks['filter_method'] == 0)#bbcode
                    {
                        $ACHTML .= $this->bbcode2html($blocks['content'],'1');
                    }
                    elseif ($blocks['filter_method'] == 1)#we're parsing raw php
                    {
                        
                            $ACHTML .= eval($blocks['content']);
                        
                    }else 
                    {
                        $ACHTML .= "block error";
                    }
                    $ACHTML .= close_menu();
                }
            return  $ACHTML;
    }


#2 Sasuun

Sasuun
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 March 2006 - 11:20 PM

so... anyone feel like tackling this?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users