[TOC] ## simple demo ``` function sp_show_msg($msg){ echo $msg."<br/>"; sleep(1); flush(); ob_flush(); } for($i=0; $i < 100; $i++){ sp_show_msg("output:".$i); } ``` ## 实战 demo(带有演示输出) > 通过输出 script 的方式进行美化输出 核心代码 ``` function sp_show_msg($msg){ echo sprintf("<script type='application/javascript'>show_msg('%s')</script>",$msg); flush(); ob_flush(); } ``` <details> <summary>描述</summary> ``` function sp_show_msg($msg){ echo sprintf("<script type='application/javascript'>show_msg('%s')</script>",$msg); sleep(1); flush(); ob_flush(); } echo <<<EOF <!doctype html> <html lang="en"> <head> <style> li{list-style: none} </style> </head> <body> <div>上</div> <div> <p>消息输出</p> <ul class="log"> </ul> </div> <div>下</div> <script> function show_msg(msg) { var log = window.document.querySelector(".log"); var li = window.document.createElement("li"); li.innerText=msg log.appendChild(li) } </script> </body> </html> EOF; flush(); ob_flush(); for($i=0; $i < 4; $i++){ sp_show_msg("output:".$i); } ``` </details> <br/>