Seeing how eval should be avoided, how do you evaluate a string as PHP code without using eval? For example consider this code:
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
$str = "\"$str\""; // Now I have a string with double quotes around it.
// how to get the contents of $str evaluated without using eval()
?>
I can get the desired result by using eval like so - eval("echo $str;");
, but eval is exactly what I am looking to avoid.
You might view this as a question of removing the double quotes. But it isn't about that. As @AmalMurali points out, what I am asking here is how to get the contents of $str evaluated without using eval()