yano3nora
7/2/2017 - 7:03 AM

[php: ob_start] stdout cache sample. #php

[php: ob_start] stdout cache sample. #php

<?php
// 関数やクラス内メソッドでHTMLをヒアドキュメント化しないで持ち回りたい時に
function testFunc(){
  ob_start();
?>
    <div class="detail">
        <div class="name"><?php the_title(); ?></div>
        <div class="date"><?php the_date(); ?></div>
    </div>
<?php
    $str = ob_get_clean();
    return $str;
}
?>