Untitled
By: a guest | Mar 20th, 2010 | Syntax:
PHP | Size: 0.78 KB | Hits: 32 | 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 ){
if( $p>strlen($str)-3 ) break;
$out .= substr($str,$offset,$p-$offset);
$tc = $str[$p+1];
if( array_key_exists($tc,$colors) ){
if($color!='') $out .= '</span>';
$out .='<span style="color:#'.$colors[$tc].'">';
$color = $tc;
}
$offset = $p + 2;
}
$out .= substr($str,$offset);
if($color!=''){
$out .= '</span>';
}else{
$out = $str;
}
return $out;
}