Entry
How to include functions from a database instead of a file?
Dec 23rd, 2000 19:55
Philip Olson, Kris Mach, http://www.php.net/manual/function.eval.php
Assuming you have a function in your database as such :
function doStuff($a)
{
$a = strtolower($a);
$a = ucwords($a);
$a = '<b>'.$a.'</b>';
Return $a;
}
You'd then run the function using : eval()
http://www.php.net/manual/function.eval.php
So, assuming the above function is pulled out of database and
named "$dbfunction" then do the following :
$a = 'Hey, what is up?';
eval($dbfunction);
print doStuff($a);
Which will then print out :
<b>Hey, What Is Up?</b>
Note: eval() has evaluated the string from database and made the
function doStuff() available just as if you included it within your
page.