DudeOnRock
DudeOnRock

Reputation: 3831

Find out execution environment for php script

Is there a way to find out if a php script is executed in a terminal that supports color control characters?

I would like to be able to execute the same script from my mac terminal or from the sublime text console without passing a flag for color support, and I would like the color control characters to be printed when run in the terminal window, but now when run from the sublime text console.

I assume this is possible, since programs like googletest have colorful output when run directly from the terminal, but don't print color control characters when executed from inside a php script.

Upvotes: 0

Views: 182

Answers (1)

Sammitch
Sammitch

Reputation: 32232

  1. You need variables_order in php.ini to contain E so that $_ENV is populated.

    # php -i | grep variables_order
    variables_order => EGPCS => EGPCS
    
  2. Check $_ENV['TERM']

  3. See if it's in this list.

Upvotes: 3

Related Questions