Jump to content

Php Code Within A String


bakunin

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

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.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...