ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 实战 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/>