William Eisert William Eisert - 1 year ago 84
PHP Question

PHP CLI, Windows 7 CMD, and CLS/FF need to get along. (Clear Win7 CMD with PHP from CLI)

Alright now, I have been searching everywhere for a way to accomplish this and apparently nobody on the internet knows what's up. And by internet I mean Google's scope of it.

I am writing a terminal application in PHP to run in the PHP CLI in the fancy command prompt of Windows 7 (x64 Ultimate). In the program, I want to clear the screen. The data displayed on the screen can be any amount of characters spanning any amount of lines. I don't want any backspace character hacks or instructions on using carriage returns. I want to clear the screen.

CMD has a fancy CLS command that does just that. So, when I run the PHP line

or any variation of executing the clear screen command (Including that one answer that said to use
system("command /C cls");
which did not work) the terminal outputs the venus symbol. The girl sign, the "upside down holy hand grenade", whatever you wish to call it. As it turns out, this is apparently some way to show the linefeed character (which if the terminal actually behaved as it should, would clear the screen.)

Why does the PHP CLI think that showing CMD a girl will make it clear the screen, and how can I get CMD to actually clear? I've tried sending it a linefeed character, sending it a girl symbol, sending it chips and cookies and all forms of nice things. Nothing worked. So the screen shall forever remain unclear, which you can imagine can be annoying when you have to re-draw something. Anyway, your help is welcome.


This is the only, yet very ugly, way of doing this, that I found working so far:

public function clearStdin()
    for ($i = 0; $i < 50; $i++) echo "\r\n";