I have a string containing HTML but which also includes PHP tags (<?php .. ?>). I’d like to let the compiler render this into pure HTML as if it were simply in a PHP file.
I know that I can do this with files by doing the following:
ob_start();
include 'my_file.php';
return ob_get_clean();
What I really want to do is something like the following:
$html = '<strong>1 + 1</strong> = <?php echo (1+1); ?>';
ob_start();
echo $html;
return ob_get_clean(); // should return '<strong>1 + 1</strong> = 2'
Asides from parsing the string and performing evals or saving the string temporarily as file; is there any way to do this in PHP when the string has been dynamically generated? Assume that I do not have privileged access so I cannot modify my php.ini.
http://php.net/manual/en/function.eval.php