PHP CLI options for windows

I am working with PHP CLI on Windows at the moment to write small command line applications.

I wanted to know if this is possible and how it is possible:

  • Clear the screen (cls will be a normal command, but exec () will not work with it)
  • Change the color, change the color of the parts of the output (previously seen in programs)
  • Make the command line horizontally larger - things quickly become unreadable

Is any of the above possibilities inside a PHP script?

+3
source share
5 answers

On Windows, in the standard command line, you cannot output color (as in Spudley's answer).

, "", "". , CLI PHP.

CLI Windows, ,

+2

. PHP

:

, , . :

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

, , . , :

<?php
echo "\033[31m".$myvar; // red foreground
echo "\033[41m".$myvar; // red background
?>

reset:

<?php
echo "\033[0m";
?>

, CLI.

, , . , , , , Windows.

, .

+1

, 2. , , ( ), , UI-.

0

Windows, PHP - . , PHP, Freebasic :

   cls
   end

. - . PHP:

<?php
   echo "This is a test\n";
   system( "cls.exe" );
   exec( "cls.exe" );
   passthru( "cls.exe" );
?>

, , " ". , PHP, escape-. PHP - cls, curses, ncurses . , - WindowBrowser (, , C), THAT . escape- . - .

What I find strange about this is that PHP was originally written in Perl, and Perl would do ncurses on Windows without any problems. Perl will also allow you to work with all escape sequences. Therefore, something happens in the Windows compilation that causes this problem.

0
source

Source: https://habr.com/ru/post/1736393/


All Articles