Zend - The PHP Company




Text

Add Code


New Terminal color function  

Type: application
Added by: joeldg
Entered: 13/12/2002
Last modified: 02/11/2001
Rating: - (fewer than 3 votes)
Views: 5361
I previously wrote up a terminal color function which called perl to do the colorizing. This is more of an update, but is a totally different function. When provided with an additional variable it will output the colorization versus passing it back as a return variable.


<?
# first define colors to use
$_colors = array(
        
LIGHT_RED      => "[1;31m",
        
LIGHT_GREEN     => "[1;32m",
        
YELLOW         => "[1;33m",
        
LIGHT_BLUE     => "[1;34m",
        
MAGENTA     => "[1;35m",
        
LIGHT_CYAN     => "[1;36m",
        
WHITE         => "[1;37m",
        
NORMAL         => "[0m",
        
BLACK         => "[0;30m",
        
RED         => "[0;31m",
        
GREEN         => "[0;32m",
        
BROWN         => "[0;33m",
        
BLUE         => "[0;34m",
        
CYAN         => "[0;36m",
        
BOLD         => "[1m",
        
UNDERSCORE     => "[4m",
        
REVERSE     => "[7m",

);
##############################################
# Output colorized text to terminal run
# php scripts..
##############################################
function termcolored($text$color="NORMAL"$back=1){
    global 
$_colors;
    
$out $_colors["$color"];
    if(
$out == ""){ $out "[0m"; }
    if(
$back){
        return 
chr(27)."$out$text".chr(27).chr(27)."[0m".chr(27);
    }else{
        echo 
chr(27)."$out$text".chr(27).chr(27)."[0m".chr(27);
    }
//fi
}// end function
#####################################################################################



Usage Example


<?
$text 
"Here is some blue text!n";
echo 
termcolored($textBLUE);
?>


Rate This Script





Search



This Category All Categories