note 103652 added to function.chr
| From: | stuart dot stanfield at gmail dot com | Date: | Tue, 26 Apr 2011 12:57:13 +0000 |
| Subject: | note 103652 added to function.chr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179160@lists.php.net to get a copy of this message | ||
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;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 77.95.99.166
----
Manual Page -- http://www.php.net/manual/en/function.chr.php
Edit -- https://master.php.net/note/edit/103652
Del: integrated -- https://master.php.net/note/delete/103652/integrated
Del: useless -- https://master.php.net/note/delete/103652/useless
Del: bad code -- https://master.php.net/note/delete/103652/bad+code
Del: spam -- https://master.php.net/note/delete/103652/spam
Del: non-english -- https://master.php.net/note/delete/103652/non-english
Del: in docs -- https://master.php.net/note/delete/103652/in+docs
Del: other reasons-- https://master.php.net/note/delete/103652
Reject -- https://master.php.net/note/reject/103652
Search -- https://master.php.net/manage/user-notes.php