[PHP][CLI]Colors

Joined
Mar 26, 2006
Messages
603
Reaction score
7
When I run a CLI application, I'm wanting to know how to change the color of the text displayed. Example: $this would come out equivalent to <font color="red">. I've looked around on google and can't find nothing. Any help or direction of where to look would be very much appreciated.

On a side note. Don't criticize about me using CLI with PHP, I know its not the best practice. But I'm wanting to learn it.

FIX:
Download:
http://freenet-homepage.de/gborn/WSHBazaar/WSHDynaCall.htm
After downloading, run make.bat.
Go to start->run type in regsvr32 dynawrap.dll
Then.
PHP:
<?PHP
$dw = new COM('DynamicWrapper');  // needs dynwrap.dll (regsvr32 dynwrap.dll)

// register needed features
$dw->Register('kernel32.dll', 'GetStdHandle', 'i=h', 'f=s', 'r=l');
$dw->Register('kernel32.dll', 'SetConsoleTextAttribute', 'i=hl', 'f=s', 'r=t');
$dw->Register('kernel32.dll', 'SetConsoleTitle', 'i=s', 'f=s', 'r=l');

// get console handle
$ch = $dw->GetStdHandle(-11);  // -11 = STD_OUTPUT_HANDLE

$dw->SetConsoleTextAttribute($ch, 14);
echo 'This is yellow text!';
$dw->SetConsoleTextAttribute($ch, 7);
echo 'Back to normal gray!';
?>
Make a bat file. Right Click->Edit.
Type
Code:
path to php folder -f path to php file made above.
pause
Code:
List of colors:
DARKBLUE = 1
DARKGREEN = 2 
DARKTEAL = 3 
DARKRED = 4 
DARKPINK = 5 
DARKYELLOW = 6 
GRAY = 7 
DARKGRAY = 8
BLUE = 9
GREEN = 10
TEAL = 11
RED = 12
PINK = 13
YELLOW = 14
WHITE = 15
Then run the .bat file.
 
Last edited:
When I run a CLI application, I'm wanting to know how to change the color of the text displayed. Example: $this would come out equivalent to <font color="red">. I've looked around on google and can't find nothing. Any help or direction of where to look would be very much appreciated.

On a side note. Don't criticize about me using CLI with PHP, I know its not the best practice. But I'm wanting to learn it.

See if there is a curses plugin. On windows, maybe something similar.

PHP itself can't do that.
 
Back