无论如何用html内容调用lambda函数?

时间:2010-11-30 06:23:21

标签: php

function sample($test1, $test2, $inner_html) {
    $html = call_user_func($inner_html);
    echo $test1 .  ' ' . $test2 . ' ' . $html;
}


sample('test1', 'test2', function(){
                    echo 'first test.'
      ?>
       <b>this is a test.</>
      <?
                    echo 'last test.';
});

1 个答案:

答案 0 :(得分:0)

如果你放了一些东西,只有在使用output controlob_start缓冲输出时才能得到那个输出:

function sample($test1, $test2, $inner_html) {
    ob_start();
    $returnValue = call_user_func($inner_html);
    $output = ob_get_clean();
    echo $test1 .  ' ' . $test2 . ' ' . $output;
}