當我把結果都秀出在畫面上,但我仍可以讓它再另外放到變數裡,接著我可以 mail 結果,或其它用途

<?php

ob_start();

echo 1;

echo 2;

$r = ob_get_contents();

ob_end_clean();

$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=utf-8';
$body = '<pre>' . print_r($r) . '</pre>';
mail('cross@ssorc.tw', 'subject', $body, implode("\r\n", $headers));

引用 : https://stackoverflow.com/questions/8770910/difference-between-ob-clean-and-ob-flush

ob_start();
print "foo";      // This never prints because ob_end_clean just empties
ob_end_clean();   //    the buffer and never prints or returns anything.

ob_start();
print "bar";      // This IS printed, but just not right here.
ob_end_flush();   // It's printed here, because ob_end_flush "prints" what's in
                  // the buffer, rather than returning it
                  //     (unlike the ob_get_* functions)

依序輸入至螢幕上 (不是等全部跑完)
引用 : http://php.net/manual/zh/function.flush.php#116485

ob_clean();
while(true){
    echo str_repeat(' ', 1024*1024*4);
    echo 'hello, world ...
';
    ob_flush();
    flush();
    usleep(1000);
}
Related posts 相關文章
WordPress 6.3 以後可能不支援 PHP 5,最低需求為 PHP 7.4
More...
你的 WordPress 升級到 PHP 8 了嗎
More...
你看 WordPress 也建議至少 PHP 7.4+ 了
More...
PHP 7 最後一版,今年也要退場了
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。