PHP 迴圈輸出 <img> 標籤,瀏覽器需等腳本結束才一次性顯示,無法即時看到。
for ($i=0; $i<10; $i++) {
echo \"
\";
ob_flush(); // 刷新 PHP 輸出緩衝
flush(); // 刷新 Web 伺服器緩衝發送給瀏覽器
sleep(1);
}
需確保 output_buffering 關閉或輸出前 ob_implicit_flush(true),且伺服器(Nginx/Apache)未啟用 proxy_buffering / gzip 緩衝。