- If the request is web or CLI it can be detected according to the existence of variables:
$env= '';
if (php_sapi_name() == 'cli') {
$env= 'cli';
} else {
$env= 'web';
}
or with one-liner
$env = (php_sapi_name() == 'cli') ? 'cli' : 'web';
- Generally insert content in a "pre" tag or perform a color highlighting in CLI, it should be indicated by a single instruction passed to the function, in case the output is required to be dumped into a text file default plane should be false.
if($env== 'cli'){
//populate cli highlighting
}elseif(){
//decorated with <pre> tag
}
- It seems to me that the user should tell the function what he wants to do with the result:
- output html.
- output CLI
- output File (plain txt)
- output json
- the number of Line in Title or Header must be passed ... 1,2,3,X and you can set the number you want footer.
or with one-liner