0

If I have a variable that contains PHP code... something like this:

$PageCode = "<?php\r\nrequire_once(\"../code/rushs_flickr_photos.php\");\r\n?>";

Is it possible to execute that code within my page and assign it back to another variable? something like:

$PageContent = exec($PageCode);
2
  • 4
    Why would you want to put PHP code in a string and execute it instead of just requiring the file directly? If your answer is because you want to get the code to execute from the user, be aware this is a huge security issue. Commented Aug 23, 2010 at 17:43
  • If you decide to fly in the face of security, just know that you don't need opening/closing php tags in code that will be eval()'d. Commented Aug 23, 2010 at 17:50

2 Answers 2

9

Yes. You are looking for eval().

This is however considered very bad practice. Whatever it is that you are trying to do, there is most likely a better way.

Sign up to request clarification or add additional context in comments.

Comments

2

Yes look at eval() function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.