Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling php function from string (with parameters)

i'd like to run a php-function dynamically by using this string:

do_lightbox('image1.jpg', 'picture 1')

i've parsed the string like this:

$exe = "do_lightbox";
$pars = "'image1.jpg', 'picture 1'";

and tried using the following code:

$rc = call_user_func($exe, $pars);

unfortunately this gives me an error - i've also tried splitting the $pars like

$pars = explode(',', $pars);

but didn't help ..

any ideas? thanks

like image 269
Fuxi Avatar asked Jun 04 '11 13:06

Fuxi


1 Answers

I think this is what you're after:

$exe = "do_lightbox";
$pars = array('image1.jpg', 'picture 1');

$rc = call_user_func_array($exe, $pars);
like image 142
James C Avatar answered Oct 12 '22 23:10

James C