Q:

How to interpret a string for php code?

I have this:
this string might contain `<?php echo $var; ?>` php code

if it was in a file, it would be just an include / require command. But this time eval wont work. What to do?

A:

The documentation of eval() says:

eval — Evaluate a string as PHP code

It also says below:

The code must not be wrapped in opening and closing PHP tags, ... It is still possible to leave and re-enter PHP mode though using the appropriate PHP tags.

Put ?> in front of your string and it will become valid PHP code (empty code) followed by some text to be sent directly to the output and more fragments of PHP code properly enclosed in the PHP tags.

