Jump to content


Photo

echo a function()


  • Please log in to reply
3 replies to this topic

#1 cjb

cjb
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 April 2006 - 10:14 PM

I have a db of functions that are called on a certain criteria. I am trying to get those from the db to be called in a page. I try to
echo $function
but all that happens is it prints the text out instead of calling the function 'function();'.

Is there some other way to echo the text function(); from a db other than using 'echo'?

#2 ypirc

ypirc
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 18 April 2006 - 10:27 PM

Did you 'echo $function();' ?

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 18 April 2006 - 11:18 PM

Does create_function help?


$row['code'] = 'return sqrt($a*$a + $b*$b);'; // from database

$foo = create_function('$a, $b', $row['code']);

$x = 3;
$y = 4;
echo $foo($x, $y);

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 cjb

cjb
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 April 2006 - 09:13 PM

Barand,

That worked, thanks.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users