Jump to content

Php Code Within A String


Recommended Posts

Is there a function to parse php code within a string ?

$string = '<?php echo 1+1 ?>';echo $string;

i want it to echo 2 but it echo the unparse code "<?php echo 1+1 ?>"The problem i have is my code is in a string and is not parsed at the beginning of the file, the sample doesn't make sens i know, but in my real code, i have a reason why its in a string. :/

Edited by bakunin
Link to comment
Share on other sites

eval() can do it:

eval("echo 1+1");

But be very careful with it, if you allow users to put information into an eval() you could have your site hacked.There most likely is a better way to do things than having your code in a string.

Edited by Ingolme
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...