AbydosGater Posted November 13, 2006 Share Posted November 13, 2006 Hi, i have my functions in my common.php, and i am pulling information from my database, i would like this information to be run as PHP,I have been told that eval() is the way to do this,But i have been reading up on eval() and im still confused on how to do it! i can see how to echo a string, but how do i run a function?how would i run a buildStats();?eval(buildStats();)??Thanks Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/ Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 So you're saying the function definition is IN the DB?If you have something like $ftest = "function test(){echo "Hello"};The following should make the function available:[code]eval($ftest);[/code]and therefore the following should display [b]Hello[/b] in your browser:[code]test();[/code]NOTE: I have NOT tested this myself but it should work. Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-123989 Share on other sites More sharing options...
AbydosGater Posted November 13, 2006 Author Share Posted November 13, 2006 will test it now thanks Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-123990 Share on other sites More sharing options...
AbydosGater Posted November 13, 2006 Author Share Posted November 13, 2006 no just tested it, and its displaying it as a string! anyone else gots any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-123995 Share on other sites More sharing options...
doni49 Posted November 13, 2006 Share Posted November 13, 2006 Can you show the code as you tried it? Try it using the code above and go from there. Once you get that simple code working, you can worry about pulling it from the DB to use it. Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-123998 Share on other sites More sharing options...
AbydosGater Posted November 13, 2006 Author Share Posted November 13, 2006 ok..Welleval($testing); is what i have in the database.. and the code that pulls the data is....[code]function buildMenu($location){$query = "SELECT * FROM agc_menus WHERE location='$location' AND active='1'";$result = mysql_query($query);while ($menurow = mysql_fetch_assoc($result)){$title = $menurow['title'];$content = $menurow['content'];echo <<<MENUITEM<table style="BORDER-COLLAPSE: collapse" height=37 cellspacing=0 width=137> <tbody> <tr> <td valign=top colspan=3 height=18 background=images/menu_top.gif> <p align=center><span style="FONT-SIZE: 7pt"><font color="#FFFFFF">$title</font></span></p> </td> </tr> <tr> <td valign=top width=9 background=images/left.gif height=96> <p> </p> </td> <td valign=top width=112 height=96> <font color="#FFFFFF">$content</font> </td> <td valign=top width=8 background=images/right.gif height=96> <p> </p> </td> </tr> <tr> <td valign=top background=images/menu_bot.gif colspan=3 height=18> <p> </p> </td> </tr> </tbody> </table> <br />MENUITEM;}};[/code]And then in my config file which is required to the file open..$testing = "echo \"hello\";";But when i run the page its just displaying the eval as a string... Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-124000 Share on other sites More sharing options...
sasa Posted November 13, 2006 Share Posted November 13, 2006 try[code]<?php$testing = "echo \"hello\";";$b = "eval(\$testing);";echo '$b is: ',$b,"\n";eval($b);echo "\n<br />\n";// or$c ='eval($testing);';eval($c);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-124109 Share on other sites More sharing options...
AbydosGater Posted November 14, 2006 Author Share Posted November 14, 2006 where do i put this? in the database?just put this in the database, and its not displaying anything! its just comming up blank! Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-124399 Share on other sites More sharing options...
doni49 Posted November 14, 2006 Share Posted November 14, 2006 in your php file. Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-124412 Share on other sites More sharing options...
AbydosGater Posted November 14, 2006 Author Share Posted November 14, 2006 Why put it in my php file? i know it would work if i put it in the file, but i want my script to pull the data from my database and parse it as php not a sting:(...would i be better using a flatfile database for this in a txt file and encrypt it?? Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-124464 Share on other sites More sharing options...
doni49 Posted November 15, 2006 Share Posted November 15, 2006 It's called Troubleshooting and Debugging. Break it down into little steps.You seem to be having trouble pulling a text string from your DB and using the eval function to read the string and create a function that works.First get eval to create a function that you can use. Then try storing that string in the DB. If it's not working now, what would you do differently with a flat file? If you know the answer to that, you should be able to get it working with the DB. Quote Link to comment https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/#findComment-124774 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.