Jump to content

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


Sasuun

Recommended Posts

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
[code]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;
    }[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.