save eval() interpreted string in variable

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
lrd089
Forum Newbie
Posts: 1
Joined: Sun Jul 14, 2002 3:46 pm

save eval() interpreted string in variable

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post 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;
Post Reply