Jump to content


Photo

Storing php in variables for later execution...


  • Please log in to reply
2 replies to this topic

#1 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 13 July 2006 - 08:54 PM

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

       
         $upload = 'ftp_put($conn, "/".$_FILES[\'ufile\'][\'name\'],    $workDir."/".$tmpName, FTP_BINARY);';
         eval($upload);
       

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

#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 13 July 2006 - 09:02 PM

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!
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 July 2006 - 09:06 PM

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

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users