You Are Here Home > How to clean the screen with PHP in Linux (cls, Linux, PHP)

How to clean the screen with PHP in Linux (cls, Linux, PHP)

Here is the trick, in your script use:

system("clear");

To make it work on both Windows and Linux:

if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
   system("cls");
else
   system("clear");

I hope this helps someone.

How to clean the screen with PHP in Linux (cls, Linux, PHP)
Filed under: Operating Systems,PHP,Programming   Posted by: Hamid

3 Comments »

  1. William:
     

    Please please please don’t do that :P .

    for ($i = 0; $i < ; $i++) { print “\n”; }

    Is way more portable.

    I know it’s not common, but some people will be running PHP on windows.

    Comment

     
  2. Codehead:
     

    William, thanks for your comment but with all respect I disagree…

    The code I posted can check for the platform and use “cls” or “clear” and your code won’t produce the desired effect for me.

    Comment

     
  3. Bil:
     

    Unfortunately neither of these solutions work on Windows 7. I have yet to find a viable solution to clearing the terminal from within a PHP script.

    Comment

     

RSS feed for comments on this post. TrackBack URL

Leave a comment