If I have a hello.php file like this:
Hello, <?php echo $foo; ?>!
I would like to do something like this in some php code:
$text = renderPhpToString('hello.php', array('foo'=>'World'));
and end up with
$text == 'Hello, World!'
Is this possible with standard PHP 5? Obviously I want more complex templates with loops and so forth..
You could use some function like this:
It uses the output buffer control function
ob_start()to buffer the following output until it’s returned byob_get_clean().Edit Make sure that you validate the data passed to this function so that
$varsdoesn’t has afileelement that would override the passed$fileargument value.