Ozh
Ozh

Reputation: 729

CLI : shell can have colors, but PHP cannot output colors, displays ← left arrow instead

I have a shell that is color capable, but I cannot have a PHP script to output colors.

For instance:

$ echo -e "\e[32m Hello"

Outputs "Hello" in green as expected, but

$ php -r 'print "\e[32m Hello\n";'

prints the following in default color:

←[32m Hello

Any clue of what I should look into ?

enter image description here

Upvotes: 0

Views: 68

Answers (1)

weirdan
weirdan

Reputation: 2632

It appears colored console output is not supposed to work reliably on windows as of yet (see PHP bug #72768 and the follow-up PR #2103). It worked on some combinations of windows/git shell/php, though.

So here's your options as far as I understand:

  • you may try to downgrade to working versions
  • try your luck with ansicon
  • use another terminal such as powershell or ConEmu
  • or wait for PHP 7.2 release where this issue is ought to be fixed

Upvotes: 1

Related Questions