Is there a clear screen command in PHP?

Thanks!

    Your thinking like Qbasic. And the answer in this case now is no. PHP has no clear screen function from my knowledge. You maybe however find a few things on the manual that'll help make your own.

      PHP is a server-side web scripting language so you can't clear the surfers screen with it, unless you count sending someone to a blank page clearing their screen. If you are trying to use PHP on the command line you could always use a system call to your operating system's clear screen command.

        Basically what I want to do is having the text overwrite itself so that it only appears as if the numbers are changing. For example in a battle sequence of my game I would want it to display like this...

        Attacker's Men : 98
        Defender's Men : 32

        And the text would keep writing over itself so that it would appear on the numbers are changing. Any advice?

        Thanks!

          If you were to use PHP to do that, you would have to keep resending the page. Your best bet would be to use Javascript to change those values, so it all happens on your user's machine.

            If yours is that global military game I saw on here, you should write that whole thing as a java applet or flash program. Those are much better solutions to a graphical game than php.

              9 years later

              I know there are better languages to do what i try, but i want to do it with PHP.

              I am trying to create a script with PHP language, so i can run it in console mode... much more like a CMD Batch (on Windows) or a Bash script on Linux...

              I can make it start and end, also echo some text on console output...

              I am not making any WebPage, no server side, etc...

              Just running a PHP script locally... typing on console:
              /path_to_php/ -f MyConsoleScript.PHP

              I also can put messages on screen by echo command...

              But how can i control where they appear... i am thinking in something like LOCATE for QBASIC, etc... and how can i "empty" the console screen, like cls on windows or clear on Linux.

              I need the script to be able to run (and work identical) on Windows and Linux.

              So as i see i can call system cls on Windows (not yet tested) and clear on Linux (neither yet tested)... i was wondering how can i check the system inside a PHP script...

              In other words how can i make this pseudo-code (the part inside the if check condition stament):

              if(System is Windows){
               passthru('cls');
              }else{
               if(System is Windows){
                passthru('clear');
               }else{
                echo "Please run it under Windows or Linux, thanks';
               }
              }
              

              Thanks in advance.

                Arrrg... passtrhu('cls'); works but do not clear the screen... only outputs this charancter: ♀

                So, how can i clean all lines of console?... i know the trick to print 10000 empty lines, but i would preffer a better way than that.

                I can not beleve there is no way to do such easy task... on PHP. It would then be impossible to create PHP applications with menus, interactive, etc... and there is also a GUI-PHP (Graphical applications programed on PHP language)... i only need PHP for batch console scripts (by the moment), maybe on a near future i will learn how to create with PHP some graphical windows and applications... i actually sue Delphi, Lazarus, etc... when i will have more knonledge on PHP i will try PHP-GSDK... etc.

                First thing i need is a way to do this tasks:
                -Read Directory entries for a real path and create an array with names
                -Iterate such array
                -Call an executable with some parameters (one of them the array item)
                -End iteration
                -Detect system (Windows or Linux) just to call the correct executable and pass the correct arguments in the correct orther (Linux version differ a little form Windows version)
                -etc...

                Need some help.

                The script i want to create... i have it done in CMD batch (windows version) and in Bash (Linux version)... but i want to convert them to justo only one (in PHP).

                The general idea of the script is to let an executable treat each file on a directory... imagine this: extract each episode from a DVD-Video and convert it to H.264/AAC dual... and name file following a pattern S##E###.mp4 ... i need some code to detect where the episodes are on DVD-Video (calling such executable with some arguments give me such info)... parse that info, extract the info i want... (where is English audio stream, etc...) and create a command line that will do the conversion, then run it
                As you can see not an easy task... since i like to control by my self the quality ans final size... i can not use any application for that... i must use scripts... worst for that... i use more than on PC to do the job in parallel (distributed computation) so less easy to find an application as i need / want to... so i create my own scripts... and use a Linux NFS central filesystem over a 100Mbit/s LAN... etc...

                Too much complicated to explain it here as you can see!!!

                So i start by first step, then will continue with the next step, etc... i do not want to jump before knowing how to stay up!!!

                Thats why i ask for the very first thing i need... clear the screen, just because it is the first sentence of my script.

                Next i will echo some literal not variable text (php echo command with fixed strings).

                Next i need to know how to read directoies.... but i think it would be the same as i do for WebServers scripts i had allready created... so i can imagine how to get them to work!!!

                Next i will need to call an executable... and such i do not know how to do it...

                Next i will need to know if the system is Windows or Linux... just to create such command properly... windows version differs on name and arguments than Linux version of the executable i want to run to extract the info i need.

                Next i need to read a file (generated by the execution of such command), i imagine there is not much difference on PHP command line than on WebServer versions, and i know for WebServers how to read, write, create and delete files and folders... so maybe similar code.

                So will all in mind i just need to know how to do this three things, just to start:
                -PHP clear console code
                -PHP detect system (Windows or Linux) code
                -PHP call an executable (Windows version on WIndows and Linux version on Linux) with arguments

                Thanks in advance for any help.

                P.D.: I preffer a direct answer, but i will also appreciate much a tutorial link about PHP console applications, thanks!

                  You'd have better luck using one of the other system commands (such as [man]system[/man]) instead of trying to copy the return value of the "cls" comamnd to the output (which is what [man]passthru[/man] does).

                    Weedpacket;11005488 wrote:

                    You'd have better luck using one of the other system commands (such as [man]system[/man]) instead of trying to copy the return value of the "cls" comamnd to the output (which is what [man]passthru[/man] does).

                    I gforgot to mention that:

                    system('cls');

                    Does exactly the same... output char: ♀

                    Same for shell_exec, etc...

                    Any other idea?

                    And, what about knowing where the script is running (Windows versus Linux)?

                    Just to be able to do this:

                    if(   something here i do not know   ){
                     // Script running on a Windows Operating System
                    }else{
                     if(   something here i do not know   ){
                      // Script running on a Linux Operating System
                     }else{
                      // Script running not on Windows nor on Linux
                    }

                    Thanks in advance!!!

                      Sorry, missing one } at end on that pseudo-code.

                        Well, this isn't really the sort of thing PHP was designed for ..... As the page for [man]system[/man] says, it also outputs the result (which, incidentally, is a form-feed character).

                        What's missing from the Windows command line is an easy way to find out how many lines it has (you can ask, but it comes with a bunch more cruft - so if you want to parse it out...). If you knew that you could just reset it with [font=monospace]mode con:lines=25;[/font] (assuming 25 lines). See Windows help about the [font=monospace]mode[/font] command.

                        For Unix-based systems, the [man]ncurses[/man] extension would be much more convenient. It hasn't been ported to Windows.

                        As for determining the operating system: PHP_OS.

                          Write a Reply...