Hi, I have tried tons of functions but none works the way I want. I have a page foo.php. Then in that I set a couple of variables. Now, if I include foo.inc.php that file can use all of these variables. Example of foo.inc.php could be:
---foo.inc.php---
<div>
<span style="font-weight: bold; margin-right: 20px"><?=$forum_dep?></span>
<span style="margin-right: 20px">TOPICS</span>
<span style="margin-right: 20px">POSTS</span>
<span style="margin-right: 20px">LAST POST</span>
</div>
---/foo.inc.php---
But now I first wish to put the contents of the included file in a variable and pass that to a function that takes a string and just puts it in a nice rounded frame. But if I use file_get_contents the php is not proberly executed. So I looked at ways to use eval to get it done. But it always seems like the executed code comes first and then the frame underneeth. Probably beacuse the phpcode is written directly once it's executed. So I looked at php.net under the eval function and found this.
function eval_mixed_helper($arr){
return ("echo stripslashes(\"".addslashes($arr[1])."\");");
}
function eval_mixed($string){
$string = "<? ?>".$string."<? ?>";
$string = preg_replace("/<\?=\s+(.*?)\s+\?>/", "<? echo $1; ?>", $string);
$string = str_replace('?>', '', str_replace( array('<?php', '<?'), '', preg_replace_callback( "/\?>((.|\n)*?)<\?/","eval_mixed_helper",$string) ) );
return eval($string);
}
But if I try that using
// output to variable
ob_start();
eval_mixed(file_get_contents(root_path . 'foo.inc.php'));
$final_html = ob_get_clean();
msgBox($final_html);
it still behaves strange. I get eval error. If I change foo.inc.php to this it works.
<?
$forum_dep = $GLOBALS['forum_department_name'];
?>
<div>
<span style="font-weight: bold; margin-right: 20px">$forum_dep</span>
<span style="margin-right: 20px">TOPICS</span>
<span style="margin-right: 20px">POSTS</span>
<span style="margin-right: 20px">LAST POST</span>
</div>
But that kind of spoils the intire idea of why I wanted to get a function like this to work. Anyone have an idea on how to get this to work?