I am trying to use include statement inside a heredoc string. But its outputting the code to the browser. I have tried using <?php include ('header.tpl'); ?> PHP: and include ('header.tpl'); PHP: but it doesnt seems to work. Would appreciate your help.
It's outputting the content of header.tpl to the browser correct? This would be because your server doesn't treat .tpl files as php. You need to add this file type to your httpd.conf file (assuming apache) so that the server treats it as php. Find the line that looks like this... AddType application/x-httpd-php .php add tpl to the end of it: AddType application/x-httpd-php .php .tpl
No that isn't the problem The code itself shows up in the browser (like below). <?php include ('header.tpl'); ?> I am able to include .tpl files with no problem except while using inside the HEREDOC string.
Only variables are parsed inside a heredoc, no any functions are parsed and called. Instead of this you can initialize some variable with "include" contents and insert this var into heredoc string: <? ob_start(); include 'include.php'; $include = ob_get_contents(); ob_end_clean(); $s = <<<EOD Contents of include: $include EOD; echo $s; ?> PHP: