Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can clear screen in php cli (like cls command) [duplicate]

Tags:

php

windows

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**
}
like image 589
Root Avatar asked Jun 20 '14 12:06

Root


People also ask

How do you clear the screen in PHP?

popen('cls', 'w'); is the way to do it.

Which command is used to clear the screen CLS?

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.

How do I clear the command line screen?

From the Windows command line or MS-DOS, you can clear the screen and all commands using the CLS command.

How do I use Clrscr in command prompt?

In Command Prompt, type: cls and press Enter. Doing this clears the entire application screen.


3 Answers

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

like image 178
M. Chris Avatar answered Sep 23 '22 12:09

M. Chris


For Windows users :

system('cls');

For Linux users :

system('clear');
like image 41
OlivierLarue Avatar answered Sep 26 '22 12:09

OlivierLarue


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.

like image 40
trejder Avatar answered Sep 26 '22 12:09

trejder