[PHP] Eval To String
Hi, Is it possible to return the result of eval function to a string rather than outputting directly to the browser? Thanks for your advice -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Eval To String
[snip] Is it possible to return the result of eval function to a string rather than outputting directly to the browser? Thanks for your advice [/snip] Yes. You're welcome. The first freakin' example in TFM http://www.php.net/eval is this; ?php $string = 'cup'; $name = 'coffee'; $str = 'This is a $string with my $name in it.'; echo $str. \n; eval(\$str = \$str\;); echo $str. \n; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Eval To String
Shaun Shaun wrote: Is it possible to return the result of eval function to a string rather than outputting directly to the browser? ob_start(); eval('$eval = evil;'); $output = ob_get_clean(); Cheers, David Grant -- David Grant http://www.grant.org.uk/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] eval() to string???
I want to evaluate some PHP code to a string. How can I do this? $php_code = "echo 'hello';" I would like to evaluate the code to "hello" in another string...
AW: [PHP] eval() to string???
try eval("\$php_code;"); -Ursprngliche Nachricht- Von: [ rswfire ] [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 24. Januar 2001 15:36 An: [EMAIL PROTECTED] Betreff: [PHP] eval() to string??? I want to evaluate some PHP code to a string. How can I do this? $php_code = "echo 'hello';" I would like to evaluate the code to "hello" in another string... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
AW: [PHP] eval() to string???
okay, i see here is an example: $php_code = "$foo + $bar"; eval("\$var = \"$php_code\";); now in $var there should be the eval of $foo + $bar -Ursprngliche Nachricht- Von: Robert S. White [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 24. Januar 2001 16:20 An: [EMAIL PROTECTED] Betreff: Re: [PHP] eval() to string??? How is this going to help me? I want to evaluate the code in $php_code to *another* string... - Original Message - From: Thomas Weber To: Php-General Sent: Wednesday, January 24, 2001 10:14 AM Subject: AW: [PHP] eval() to string??? try eval("\$php_code;"); -Ursprngliche Nachricht- Von: [ rswfire ] [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 24. Januar 2001 15:36 An: [EMAIL PROTECTED] Betreff: [PHP] eval() to string??? I want to evaluate some PHP code to a string. How can I do this? $php_code = "echo 'hello';" I would like to evaluate the code to "hello" in another string... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] eval() to string???
Hi, I want to evaluate the code in $php_code to *another* string... you have to do it through output buffering: ob_start(); eval($php_code); $another_string=ob_get_contents(); ob_end_clean(); Rgds, Tfr --== [EMAIL PROTECTED] == http://tfr.cafe.ee/ == +372-50-17621 ==-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: AW: [PHP] eval() to string???
-Ursprngliche Nachricht- Von: Robert S. White [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 24. Januar 2001 16:20 An: [EMAIL PROTECTED] Betreff: Re: [PHP] eval() to string??? How is this going to help me? I want to evaluate the code in $php_code to *another* string... From http://www.php.net/manual/en/function.eval.php : "A return statement will terminate the evaluation of the string immediatley. In PHP 4 you may use return to return a value that will become the result of the eval() function while in PHP 3 eval() was of type void and did never return anything." So, if you're using PHP4, just ensure that there is a return in$php_code that returns the desired value: $thing = eval($php_code); It's helpful to read the notes at the above URL - escaping things correctly for eval() can be tricky... - steve - Original Message - From: Thomas Weber To: Php-General Sent: Wednesday, January 24, 2001 10:14 AM Subject: AW: [PHP] eval() to string??? try eval("\$php_code;"); -Ursprngliche Nachricht- Von: [ rswfire ] [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 24. Januar 2001 15:36 An: [EMAIL PROTECTED] Betreff: [PHP] eval() to string??? I want to evaluate some PHP code to a string. How can I do this? $php_code = "echo 'hello';" I would like to evaluate the code to "hello" in another string... -- -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]