note 89488 added to function.chr

From: Date: Tue, 10 Mar 2009 19:27:28 +0000
Subject: note 89488 added to function.chr
Groups: php.notes 
Request: Send a blank email to php-notes+get-151697@lists.php.net to get a copy of this message
Thank you joeldegan for your termcolored function. I write a lot of command-line scripts using PHP and like to colorize them. I was having a problem with the termcolored function where the next character echo'ed after calling termcolored() was being dropped. Turns out you don't need the extra chr(27) at the end of each term color code. Here's my modified version of your function, renamed to echocolor. <? function echocolor($text,$color="normal",$back=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" ); $out = $colors["$color"]; $ech = chr(27)."$out"."$text".chr(27)."[0m"; if($back) { return $ech; } else { echo $ech; } } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 206.66.146.23 ---- Manual Page -- http://www.php.net/manual/en/function.chr.php Edit -- https://master.php.net/note/edit/89488 Del: integrated -- https://master.php.net/note/delete/89488/integrated Del: useless -- https://master.php.net/note/delete/89488/useless Del: bad code -- https://master.php.net/note/delete/89488/bad+code Del: spam -- https://master.php.net/note/delete/89488/spam Del: non-english -- https://master.php.net/note/delete/89488/non-english Del: in docs -- https://master.php.net/note/delete/89488/in+docs Del: other reasons-- https://master.php.net/note/delete/89488 Reject -- https://master.php.net/note/reject/89488 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151697) next »