AncientSage Posted July 13, 2006 Share Posted July 13, 2006 Hello,I want to store php code inside a php variable, but not have it executed until called by the eval() function, if that is, how you would do it. However, I'd guess you put quotes around the code you want to execute later, but my code has some quotes in it, therefore, I must use a back-slash to escape them, that's where I'd guess I run into the problem. Does eval() execute the back-slashes, or do I have to use the explode (or implode, whichever is needed) function to make it work correctly?For example... [code] $upload = 'ftp_put($conn, "/".$_FILES[\'ufile\'][\'name\'], $workDir."/".$tmpName, FTP_BINARY);'; eval($upload); [/code]Is there even a need to put quotes around the code to make it so it does not execute when the variable is read? I've never used the eval() function before on another note... Quote Link to comment https://forums.phpfreaks.com/topic/14530-storing-php-in-variables-for-later-execution/ Share on other sites More sharing options...
ShogunWarrior Posted July 13, 2006 Share Posted July 13, 2006 No, when you escape a character in a string the backslash is lost as soon as PHP stores the string in memory, from then on it is stored in un-quoted form.As long as you escape the quotes properly everything should be fine.PS: Eval incurs quite a performance drag if it's an intensive operation! Quote Link to comment https://forums.phpfreaks.com/topic/14530-storing-php-in-variables-for-later-execution/#findComment-57588 Share on other sites More sharing options...
kenrbnsn Posted July 13, 2006 Share Posted July 13, 2006 On more comment on eval() ... your string must be prefixed with "<?php " and suffixed with " ?>" or eval() will not work correctly.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14530-storing-php-in-variables-for-later-execution/#findComment-57590 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.