Re: How to assign eval() to variable?
| From: | Stuart | Date: | Sat, 23 May 2009 13:43:35 +0000 |
| Subject: | Re: How to assign eval() to variable? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-293016@lists.php.net to get a copy of this message | ||
2009/5/23 Afan Pasalic <afan@afan.net>:
> short hack works like a charm!
> :-)
It may work but output buffers are relatively expensive. The eval
function will return the value the eval'd code returns, so just stick
a return statement at the end of the string you're eval'ing.
Suggestions...
> oorza2k5@gmail.com wrote:
>>
>> short hack, assuming your eval echo's out to the browser (which I can't
>> see how else you'd expect something to 'return' from an eval'd
>> statement
>> ob_start();
>> eval($foo);
>> $result = ob_get_clean();
>>
>> On May 23, 2009 1:46am, Afan Pasalic <afan@afan.net> wrote:
>> > hi,
>> >
>> > I have on one website boxes with information, pulled from mysql. the
>> > content can be string, php code, url of other website or url to specific
>> > file etc.
>> >
>> >
>> >
>> > currently, I have something like this:
>> >
>> >
>> >
>> > // connect to db
>> >
>> > // mysql_query() to get box content and content_type
>> >
>> >
>> >
>> > switch($content_type)
>> >
>> > {
>> >
>> > case 'string':
>> >
>> > echo $content;
>> >
>> > break;
>> >
>> >
>> >
>> > case 'php_code':
>> >
>> > eval($content);
>> >
>> > break;
>> >
>> >
>> >
>> > case 'website':
>> >
>> > echo ''.$content.';
>> >
>> > break;
>> >
>> >
>> >
>> > case 'file'
>> >
>> > require_once($file);
>> >
>> > echo $file_content;
>> >
>> >
>> >
>> > // etc.
>> >
>> > }
>> >
>> >
>> >
>> > but, now I have to change the code to assign content to variable and the
>> > variable will be printed later. I tried something like this:
>> >
>> >
>> >
>> >
>> >
>> > switch($content_type)
>> >
>> > {
>> >
>> > case 'string':
>> >
>> > $record = $content;
>> >
>> > break;
>> >
>> >
>> >
>> > case 'php_code':
>> >
>> > $record = eval($content);
>> >
>> > break;
>> >
>> >
>> >
>> > case 'website':
>> >
>> > $record = ''.$content.';
>> >
>> > break;
>> >
>> >
>> >
>> > case 'file'
>> >
>> > require_once($file);
>> >
>> > $record = $file_content;
>> >
>> >
>> >
>> > // etc.
>> >
>> > }
>> >
>> >
>> >
>> > and it works - except eval() part. cant do $record = eval($content);
>> > ?!?!?!?
>> >
>> >
>> >
>> > thanks
>> >
>> >
>> >
>> >
>> >
>> > afan
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > --
>> >
>> > PHP General Mailing List (http://www.php.net/)
>> >
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>