Page 1 of 1

Making PHP clear the screen

PostPosted: 27. December 2008 21:18
by lolio
I'm trying to make a CLI program using PHP but want it to have a nice menu to be easy to use. However In order to do this I need to be able to clear the screen.
I have tried the following few bits of code and none of them seem to work under XAMPP.
Code: Select all
exec('command /C cls');

passthru('command /C cls');

function clearscreen($out = TRUE) {
    $clearscreen = chr(27)."[H".chr(27)."[2J";
    if ($out) print $clearscreen;
    else return $clearscreen;
}
clearscreen();

All that happens is some weird characters get displayed on screen. I've even tried having a file called clearscreen.cmd which works fine when run from the command line but when called from PHP it too just displays the same weird characters. I've had a look through my php.ini file but can't find anything that would seem to cause this. This happened on XAMPP 1.6.8 and still happens now I've updated to 1.7.0.

Does anyone know why this happens and how I can fix it?

Re: Making PHP clear the screen

PostPosted: 28. December 2008 02:37
by Sharley
Try posting this in the PHP forum as it may be quicker and there are some English speakers who visit that forum who may be able to help.

BTW don't try and machine translate into German or they will not understand it. ;)
Good luck.

Re: Making PHP clear the screen

PostPosted: 28. December 2008 03:19
by lolio
OK done, thanks.