When PHP script run from command line (windows) , how can clear the console screen from script .
for example :
while(true){
// sleep for 10 seconds , then clear the console
sleep(10);
// below command execute to clear the console windows
**COMMAND**
}
popen('cls', 'w'); is the way to do it.
In computing, CLS (for clear screen) is a command used by the command-line interpreters COMMAND.COM and cmd.exe on DOS, Digital Research FlexOS, IBM OS/2, Microsoft Windows and ReactOS operating systems to clear the screen or console window of commands and any output generated by them.
From the Windows command line or MS-DOS, you can clear the screen and all commands using the CLS command.
In Command Prompt, type: cls and press Enter. Doing this clears the entire application screen.
If you did not have any luck with the solutions above, consider the following
echo chr(27).chr(91).'H'.chr(27).chr(91).'J'; //^[H^[J
Hope it will help.
Source : http://pank.org/blog/2011/02/php-clear-terminal-screen.html
For Windows users :
system('cls');
For Linux users :
system('clear');
Found a solution, that works in both cmd
and GitBash. However, this is the ugliest implementation of clearing console-screen I can think of. Pity, that there isn't any working alternative.
The "magic" is to... poke console with fifty new-lines, like that:
public function clearStdin()
{
for ($i = 0; $i < 50; $i++) echo "\r\n";
}
This is a modified (fixed?) version of this non-working (for me) post from 2006.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With