Jump to content

Archived

This topic is now archived and is closed to further replies.

AncientSage

Storing php in variables for later execution...

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...

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites
On more comment on eval() ... your string must be prefixed with "<?php " and suffixed with " ?>" or eval() will not work correctly.

Ken

Share this post


Link to post
Share on other sites

×

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.