This could be very helpful, for example if you want to use a module or a template, you may have a php script in a string, just like that:
If you loads that text in a string, and echo it to the html page, it will not be executed by php.
$string = "Hello ?> . You are wellcome !";
echo $string;
?>
If you have only a php script in a string, you just use eval() to execute:
$string = "echo $username; ";
eval ( $string ) ;
?>
echo $username;
?>
$username = "SMITH" ;
$string = "Hello . You are wellcome !";
// This will search for the php script in the string:
$pos = strpos( $tmp ,"" ) ;
$pos2 = strpos ( $tmp , "?>" , $pos ) ;
$scr = substr($tmp,$pos + 5 , $pos2 - $pos -3 ) ;
//This will execute the script.
echo substr($tmp,0,$pos);
eval( " $scr " );
echo substr($tmp,$pos2+2);
?>
Display: