As Dagon said it's a really really bad idea to do what you're asking. You should only do it when you have NO other options, and you can 100% trust your input (Only you use the server and its local host, even then I would find another way)
I'll point you in the direction of the manual with another reiteration of the warning, you will want to find a different way to do this.
http://www.phpbuilder.com/manual/function.eval.php
$str = "hello, I'm <? rand(12,28);?> years old.";
$str = str_replace('<?', '".', $str);
$str = str_replace('?>', '."', $str);
$str = str_replace(';', '', $str);
echo $str. "<br/>";
eval("\$str = \"$str\";");
echo $str. "<br/>";
The obvious concern here is that if you are accepting user input then evaluating what comes out, I can do some very evil things.