Log in

View Full Version : specific syntax question -- variable function names



djr33
05-24-2006, 05:39 PM
These aren't related to a particular problem, but would save me time in the future (and with old scripts) if there's a way to use them.


As with variable variables, can you have variable functions?
For example, it's annoying to check "if jpeg, ... imagecreatefromJPEG... if gif..."
Is there a way to do "imagecreatefrom$imgtype"?
That's wrong, I know, but is there a correct way?
Hmm.... maybe the eval function if that was stored as a string. Better way, though?




Y'know... I had another semi-unrelated question and I can't remember it now. I'll post when I do, I guess.

Twey
05-24-2006, 05:47 PM
Yes.
I'm not entirely sure if you can do imgCreateFrom$imgtype, but you can do:
$imgfunc = "imageCreateFromJPEG";
$imgfunc($file);

djr33
05-24-2006, 05:50 PM
Ok.
So...


$imgfunc = "imageCreateFrom".strtoupper($filetype);
$imgfunc($file);

Right?

thanks :)