moving companies : Computers : Programming : Languages : PHP : Function Libraries

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

14 of 16 people (88%) answered Yes
Recently 8 of 10 people (80%) answered Yes

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.