如何在php cli中清除屏幕(如cls命令)

2022-08-30 16:22:15

当PHP脚本从命令行(windows)运行时,如何从脚本中清除控制台屏幕。

例如:

while(true){
    // sleep for 10 seconds , then clear the console
    sleep(10);

    // below command execute to clear the console windows
    **COMMAND**
}

答案 1

如果您对上述解决方案没有任何运气,请考虑以下几点

echo chr(27).chr(91).'H'.chr(27).chr(91).'J';   //^[H^[J  

希望它会有所帮助。

来源 : http://pank.org/blog/2011/02/php-clear-terminal-screen.html


答案 2

对于视窗用户:

system('cls');

对于 Linux 用户:

system('clear');

推荐