note 103652 deleted from function.chr by danbrown
| From: | danbrown@php.net | Date: | Tue, 26 Apr 2011 14:44:03 +0000 |
| Subject: | note 103652 deleted from function.chr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179163@lists.php.net to get a copy of this message | ||
Note Submitter: stuart dot stanfield at gmail dot com
----
Thanks to glen at glencooper dot com, I've taken his existing function and added support for
background colours, as well as being able to accept an array (allows you to specify things like bold
blink red ;)), and also things like blink.
Here's the code:
<?php
function echocolor($text,$color="normal",$bg=0,$ret=0)
{
$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", 'blink' => "[5m" );
$backgrounds = array('black' => "[0;40m", 'red' =>
"[0;41m", 'green' => "[0;42m", 'brown' =>
"[0;43m", 'blue' => "[0;44m", 'magenta' =>
"[0;45m", 'cyan' => "[0;46m", 'white' =>
'[0;47m');
$out = "";
if (!is_numeric($bg)) {
$out .= chr(27).$backgrounds[$bg];
}
if (!is_array($color)) {
$out .= chr(27).$colors["$color"];
} else {
foreach($color as $cl) {
$out .= chr(27).$colors[$cl];
}
}
$ech = $out.$text.chr(27)."[0m";
if($ret)
{
return $ech;
}
else
{
echo $ech;
}
}
?>