christo16 Posted May 19, 2007 Share Posted May 19, 2007 Hello, I would like to store php code into a variable, heres an example: function test ($var) { $var; //I also tried echo $var; return; } $string = "echo \"test\" "; test ($string); When it works, it will only output "echo test", instead of just "test". Thank you for any help! Link to comment https://forums.phpfreaks.com/topic/52140-storing-php-code-as-a-variable/ Share on other sites More sharing options...
zack45668 Posted May 19, 2007 Share Posted May 19, 2007 Try this $string = echo "test"; test ($string); Link to comment https://forums.phpfreaks.com/topic/52140-storing-php-code-as-a-variable/#findComment-257178 Share on other sites More sharing options...
utexas_pjm Posted May 19, 2007 Share Posted May 19, 2007 You want to use eval(). Here's the documentation: http://us2.php.net/eval. Best, Patrick Link to comment https://forums.phpfreaks.com/topic/52140-storing-php-code-as-a-variable/#findComment-257187 Share on other sites More sharing options...
lewis987 Posted May 19, 2007 Share Posted May 19, 2007 try this instead (tested and working) function test ($var) { echo $var; //I also tried echo $var; return; } $string = "test"; test ($string); } Link to comment https://forums.phpfreaks.com/topic/52140-storing-php-code-as-a-variable/#findComment-257217 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.