So I have the following code:
$string = "<p>the year is currently <!--CODE return date('Y'); CODE-->, it's been a good year until I bent my iPhone</p>";
$string = preg_replace_callback('/<!--CODE(.*?)CODE-->/',
function($groups) { return eval($groups[1]); },
$string);
echo $string;
What this does is replaces specific HTML comments that are retrieved from a database entry of HTML. It works fine when using return but if I echo or include an external file then the content will appear before the start of the string, so in the example string above, the content will be inserted before the p element.
I have output buffering on so I'm thinking it might be eval(). can anyone confirm this for me or suggest how I can use include and have it inserted where intended?
Appreciate your input, thanks.