清除CMD-shell与php [英] Clear CMD-shell with php
本文介绍了清除CMD-shell与php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个简单的php脚本,每秒输出一个字符串。
I have this simple php script which outputs a string every second.
<?php
$i = 1;
while(1)
{
exec("cls"); //<- Does not work
echo "test_".$i."\n";
sleep(1);
$i++;
}
我在Windows上的命令shell中执行脚本( php myscript.php
),并尝试在每个周期之前清除命令shell。但我不会让它工作。任何想法?
I execute the script in the command shell on windows (php myscript.php
) and try to clear the command shell before every cycle. But I don't get it to work. Any ideas?
推荐答案
如何?
<?php
$i = 1;
echo str_repeat("\n", 300); // Clears buffer history, only executes once
while(1)
{
echo "test_".$i."\r"; // Now uses carriage return instead of new line
sleep(1);
$i++;
}
str_repeat()
函数在和
循环之外执行,而不是用一个新行结束每个回声,它将指针移回到现有行,并在其顶部写入。
the str_repeat()
function executes outside of the while
loop, and instead of ending each echo with a new line, it moves the pointer back to the existing line, and writes over the top of it.
这篇关于清除CMD-shell与php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文