Page 1 of 1

save eval() interpreted string in variable

Posted: Sun Jul 14, 2002 3:46 pm
by lrd089
hey guys!

how can I save an eval() interpreted string in a variable? I tried s.th. like this,

Code: Select all

$test = eval($string);
but the $string is just put interpreted at the top of the site and the rest of the script follows usual.

THX lrd089

Posted: Mon Jul 15, 2002 1:46 am
by volka
any variable that has been set during eval() is available according to the scope it has been set.
i.e. if you set $_GLOBALS['xyz'] within your evaluated string it will be globally there after eval().

take a look at the first example of theeval()-manual

Posted: Mon Jul 15, 2002 3:57 am
by gnu2php
I'm not sure if this is what you had in mind, but if I understand correctly--you are using eval() at the beginning of your script, but you don't want its output to be at the top.

If so, you can use "output buffering":

Code: Select all

ob_start();   // Start the output buffer

eval( . . . );

$output = ob_get_contents();   // Get outputted data

// Erase output buffer, since we already have its contents
ob_end_clean();
Then later in your script, you can:

Code: Select all

print $output;