note 99077 added to function.chr
| From: | alex dot chesser at gmail dot com | Date: | Mon, 26 Jul 2010 15:17:27 +0000 |
| Subject: | note 99077 added to function.chr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171141@lists.php.net to get a copy of this message | ||
Thanks to Glen Cooper for the initial function. I've modified and tweaked to get the structure
of being able to specify background and foreground colors.
<?php
function ec2($text, $fg = null, $bg = null, $d = 'normal') {
$colors = array( 'black' => 0,
'red' => 1,
'green' => 2,
'yellow' => 3,
'blue' => 4,
'magenta' => 5,
'cyan' => 6,
'white' => 7);
$decoration = array ( 'normal' => 0,
'bold' => 1,
'underline' => 4,
'reverse' => 7);
$fg = $fg ? "3{$colors[$fg]}m" : "32m";
$bg = $bg ? "4{$colors[$bg]};" : null;
$d = "[{$decoration[$d]};";
echo chr(27)."$d$bg$fg"."$text".chr(27)."[0m";
}
$text = "Here is some text\n";
ec2($text, 'black', 'white');
ec2($text, 'blue', 'white', 'underline');
ec2($text, 'green', null, 'bold');
?>
I've based it on the definition found here:
http://en.wikipedia.org/wiki/ANSI_escape_code
I'm sure there is a lot of further improvement that can be done... but it's a step.
----
Server IP: 69.147.83.197
Probable Submitter: 173.34.33.13
----
Manual Page -- http://www.php.net/manual/en/function.chr.php
Edit -- https://master.php.net/note/edit/99077
Del: integrated -- https://master.php.net/note/delete/99077/integrated
Del: useless -- https://master.php.net/note/delete/99077/useless
Del: bad code -- https://master.php.net/note/delete/99077/bad+code
Del: spam -- https://master.php.net/note/delete/99077/spam
Del: non-english -- https://master.php.net/note/delete/99077/non-english
Del: in docs -- https://master.php.net/note/delete/99077/in+docs
Del: other reasons-- https://master.php.net/note/delete/99077
Reject -- https://master.php.net/note/reject/99077
Search -- https://master.php.net/manage/user-notes.php