我有这个简单的 php 脚本,它每秒输出一个字符串。
<?php
$i = 1;
while(1)
{
exec("cls"); //<- Does not work
echo "test_".$i."\n";
sleep(1);
$i++;
}
我在 Windows 上的命令 shell 中执行脚本(php myscript.php
)并尝试在每个周期之前清除命令外壳。但我无法让它发挥作用。有任何想法吗?
这个怎么样?
<?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++;
}
the str_repeat()
函数在外部执行while
循环,并且不是用新行结束每个回显,而是将指针移回到现有行,并在其顶部写入。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)