PHP: Detect if you are outputting to the CLI

I needed to know if my PHP was outputting to the CLI in text mode, or to a browser in HTML mode. The following simple function will tell you if you are in CLI mode.

function is_cli() {
    if (php_sapi_name() == 'cli') {
        return true;
    }

    return false;
}


Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 3.133.109.211
To prevent spam please submit by clicking the kitten: