dwees Posted October 10, 2006 Share Posted October 10, 2006 Hi there,I've written some Javascript that uses the new Canvas element to produce images in HTML, which is great, but the images aren't permanent, and I'd like to make them so. Also, Canvas isn't supported in all browsers, and seems lack text capability and anti-aliasing to create sharp pictures.So I'd like to start from scratch and recode the whole thing in PHP, and I thought a good idea would be to basically convert as much of the code as I can directly from the Javascript, then work around the details, and use $_POST to send the data from the client side back to the server, then return an image depending on what information the server-side script receives, and even better, using PHP I could cache the images so that if an identical call is made by the user, I can just immediately return the image. All of this seems like it won't be an issue for me, however...In the Javascript I have a pair of nested functions defined like so:[code]function f(x, fu) { var myfunction = new Function("x", "return "+ fu + ";") return myfunction (x);}[/code]where x is a number, and fu is a string. When I do this, I can construct the required function from the user input, and then use that constructed function to modify the number x. Basically the myfunction is not strictly defined, and the definition can be adjusted at runtime.Is this type of definition possibly in PHP? I took a look at my one skinny PHP book I have, and I didn't see any examples of how to do this, so before I go and buy a more expensive fat PHP book, I thought I'd ask around and see if anyone can help me with this.Thanks in advance,Dave Link to comment https://forums.phpfreaks.com/topic/23565-loose-function-definitions/ Share on other sites More sharing options...
michaellunsford Posted October 10, 2006 Share Posted October 10, 2006 I've done something like this using eval();http://usphp.com/eval Link to comment https://forums.phpfreaks.com/topic/23565-loose-function-definitions/#findComment-106957 Share on other sites More sharing options...
dwees Posted October 10, 2006 Author Share Posted October 10, 2006 Thanks for the super fast response, Eval looks like what I want to use. Dave Link to comment https://forums.phpfreaks.com/topic/23565-loose-function-definitions/#findComment-106959 Share on other sites More sharing options...
kenrbnsn Posted October 10, 2006 Share Posted October 10, 2006 You should also look at the function [url=http://www.php.net/create_function]create_function()[/url]. This may be closer to your original idea.Ken Link to comment https://forums.phpfreaks.com/topic/23565-loose-function-definitions/#findComment-107055 Share on other sites More sharing options...
dwees Posted October 11, 2006 Author Share Posted October 11, 2006 This create_function thing has virtually identical syntax to what I was using in Javascript, thanks!I'm pretty sure I can work it around either way, but option #2 is closer to what I was doing in Javascript. Actually, if you include a var $newfunc = etc... it's identical syntax.Dave Link to comment https://forums.phpfreaks.com/topic/23565-loose-function-definitions/#findComment-107305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.