ob_get_contents + ob_end_clean vs ob_get_clean

前端 未结 4 1464
星月不相逢
星月不相逢 2020-12-15 16:28

Is there any difference between these two pieces of PHP?

ob_start();
//code...
$pageContent = ob_get_contents();
ob_end_clean();
someFunction($pageContent);
         


        
4条回答
  •  无人及你
    2020-12-15 17:03

    ob_get_contents() can be used to continue the output buffering.

    Example:

    ob_start();
    echo 'Something!';
    $html1 = ob_get_contents();
    echo 'More to say!';
    $html2 = ob_get_contents();
    ob_end_clean();
    

    At the end the vars have this content:

    $html1 = 'Something!';
    $html2 = 'Something!More to say!';
    

提交回复
热议问题