how to put include(phpfile) to variable?
I want like theme or template untouched like default then other php can use it as their theme. but i have problem that i cant put theme to variable with generated before output print.
example here:
main code:
$word[0]开发者_StackOverflow中文版 = "test";
$word[1] = "hello word";
$word[2] = "example";
$word[3] = "wordwordword";
$word[4] = "variable";
while(5)
{
$name = "TEST".$word[$i];
output .= include("theme.php");
$i++;
}
echo "OUTPUT:";
echo "TITLE";
echo $output;
theme.php code:
hello <?php echo $name; ?>
NOTE: i know while loop will break but this is just example code. because i use while(mysql_fetch_array($result)). thanks
That code can't possible work, so I reckon it's pseudo code. Anyway, the issue is fixed with use of the ob_* functions in PHP, as follows. This is how the majority of template parsers in php work:
<?php
$word = array( );
$word[0] = "test";
$word[1] = "hello word";
$word[2] = "example";
$word[3] = "wordwordword";
$word[4] = "variable";
$i = 0;
for( $i = 0, $j = count( $word ); $i < $j; $i ++ ) {
$name = "TEST" . $word[$i];
ob_start( );
include( 'theme.php' );
$output .= ob_get_clean( );
}
echo $output;
/**
* Result:
*
* TESTtest
* TESThello world
* TESTexample
* TESTwordwordword
* TESTvariable
*/
精彩评论