evaluate code php in string using the function eval(): this post Execute PHP code in a string
Welcome
';
eval("?> $str
http://codepad.org/ao2PPHN7
also if your need the code buffer output in a string also you can using the ob_start() method:
Hello
;
';