EchoFool Posted April 10, 2009 Share Posted April 10, 2009 I have a code which alters quite frequently so i save the php code for the script in a database table, and assign it to a variable for the script to attempt to read it as normal scripting language without errors.. How ever i have a problem because this is pretty much what im trying here: <?php $function = 'If($me == 2){'; $function."echo 'fail';}Else{"; ?> <input type="checkbox" name="list[]" value="<?php echo $value;?>"> <?php } ?> Now this obviously gives me an unexpected } error.. which is where im stuck. The idea is the script would read it naturally as php like so based on what is in the $funcation variable: <?php If($me == 2){echo 'fail';}Else{ ?> <input type="checkbox" name="list[]" value="<?php echo $value;?>"> <?php } ?> Any thoughts on how i can go about this ? If at all possible in php? Hope you can help! Quote Link to comment https://forums.phpfreaks.com/topic/153423-solved-help-with-passing-php-scripts-in-a-variable-and-execute-them/ Share on other sites More sharing options...
ratcateme Posted April 10, 2009 Share Posted April 10, 2009 how do you mean it alters is it at all possible for say one or two vars to alter but the core code remain the same the you could store just those 2 in the database? but if you want to do code inside a var checkout eval you might be able to go say: <?php $function = "If($me == 2){ echo 'fail';}Else{ echo '<input type=\"checkbox\" name=\"list[]\" value=\"$value\">'; }"; eval($function); ?> i think Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153423-solved-help-with-passing-php-scripts-in-a-variable-and-execute-them/#findComment-806081 Share on other sites More sharing options...
EchoFool Posted April 10, 2009 Author Share Posted April 10, 2009 how do you mean it alters is it at all possible for say one or two vars to alter but the core code remain the same the you could store just those 2 in the database? but if you want to do code inside a var checkout eval you might be able to go say: <?php $function = "If($me == 2){ echo 'fail';}Else{ echo '<input type=\"checkbox\" name=\"list[]\" value=\"$value\">'; }"; eval($function); ?> i think Scott. It alters from IF statements to while loop or neither depending on user's choice on what they need to view. I tried eval and it returned: Parse error: parse error : eval()'d code on line 1 Is there a way to echo the Eval() text inside it to see what is causing the error ? Quote Link to comment https://forums.phpfreaks.com/topic/153423-solved-help-with-passing-php-scripts-in-a-variable-and-execute-them/#findComment-806083 Share on other sites More sharing options...
ratcateme Posted April 10, 2009 Share Posted April 10, 2009 looking at that i just was thinking you need to escape $'s like this $function = "if(\$me == 2){ echo 'fail';}else{ echo '<input type=\"checkbox\" name=\"list[]\" value=\"\$value\">'; }"; also i think the if and else should be lower case but i don't think it matters Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153423-solved-help-with-passing-php-scripts-in-a-variable-and-execute-them/#findComment-806085 Share on other sites More sharing options...
EchoFool Posted April 10, 2009 Author Share Posted April 10, 2009 Thank you Scott Quote Link to comment https://forums.phpfreaks.com/topic/153423-solved-help-with-passing-php-scripts-in-a-variable-and-execute-them/#findComment-806090 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.