Jump to content

Storing php in variables for later execution...


AncientSage

Recommended Posts

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...
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.