Untitled
By: a guest | Mar 20th, 2010 | Syntax:
PHP | Size: 0.81 KB | Hits: 69 | Expires: Never
function AddColorCodes($str){
$out='';
$colors = array('0'=>'000',
'1'=>'008',
'2'=>'00f',
'3'=>'090',
'4'=>'099',
'5'=>'0f0',
'6'=>'0ff',
'7'=>'800',
'8'=>'808',
'9'=>'990',
'a'=>'888',
'b'=>'ccc',
'c'=>'f00',
'd'=>'f0f',
'e'=>'ff0',
'f'=>'fff' );
$offset=0;
$color='';
while( ($p = strpos($str,'&',$offset))!==FALSE ){
$out .= substr($str,$offset,$p-$offset);
if( $p>strlen($str)-3 ){
$offset = strlen($str);
break;
}
$tc = $str[$p+1];
if( array_key_exists($tc,$colors) && $color != $tc ){
if($color!='') $out .= '</span>';
$out .='<span style="color:#'.$colors[$tc].'">';
$color = $tc;
}
$offset = $p + 2;
}
$out .= substr($str,$offset);
if($color!=''){
$out .= '</span>';
}
return $out;
}