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++;
}
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?
can you check this solution
How about this?
the
str_repeat()
function executes outside of thewhile
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.Apparently, you have to store the output of the variable and then
print
it to have it clear the screen successfully:All together:
I tested it on Linux with
clear
instead ofcls
(the equivalent command) and it worked fine.Duplicate of ➝ this question
Under Windows, no such thing as
Sorry! All you could possibly do is hunt for an executable (not the cmd built-in command) like here...
You have to print the output to the terminal:
if it is linux server use following command (
clear
) if it is window server usecls
i hope it will worksecond solution
This one worked for me, tested also.