assuming you are basically trying to convert the ^x codes, I'll just paste what i use to convert hostnames / playernames into something html can display :
<?php
function WriteColor($str) {
codepage_convert ($str);
$foundstart = False;
$tmp = '';
for ($i = 0; $i < strlen(trim($str)); $i++) {
if (($str[$i] == '^') And (ereg("[0-8]", $str[$i+1]))) {
if (!$foundstart) {
$tmp .= '<FONT COLOR="'.getcolorcode($str[$i+1]).'">';
$foundstart = True;
} else {
$tmp .= '</FONT><FONT COLOR="'.getcolorcode($str[$i+1]).'">';
}
$i++;
} else if ($str[$i] == "^" && $str[$i+1] == 9) {
$tmp .= "</FONT>";
$i++;
} else {
$tmp .= $str[$i];
}
}
if ($foundstart) {
$str = $tmp.'</FONT>';
}
return $str;
}
function getcolorcode($type) {
switch ($type) {
case 0 : $type = "#000000"; return $type; Break;
case 1 : $type = "#FF0000"; return $type; Break;
case 2 : $type = "#00FF00"; return $type; Break;
case 3 : $type = "#FFFF00"; return $type; Break;
case 4 : $type = "#0000FF"; return $type; Break;
case 5 : $type = "#FF00FF"; return $type; Break;
case 6 : $type = "#00FFFF"; return $type; Break;
case 7 : $type = "#FFFFFF"; return $type; Break;
case 8 : $type = "#000000"; return $type; Break;
case 9 : $type = "#000000"; return $type; Break;
return $type;
}
}
function UnWriteColor($str) {
$tmp = '';
for ($i = 0; $i < strlen($str); $i++) {
if (($str[$i] == '^') And (ereg("[0-8]", $str[$i+1]))) {
$i+=1;
} else {
$tmp .= $str[$i];
}
}
$str = $tmp;
return $str;
}
function codepage_convert (&$str) {
global $cp_tables;
$newstr = "";
$current_cp = "L";
$len = strlen ($str);
for ($i=0; $i<$len; $i++) {
if ($str{$i} == "^" && is_array ($cp_tables[$str{$i+1}])) {
$i++;
$current_cp = $str{$i};
continue;
}
$decimal = ord ($str{$i});
if ($decimal > 127) $newstr .= sprintf ("&#%05d;", $cp_tables[$current_cp][$decimal]);
else $newstr .= $str{$i};
}
$str = $newstr;
}
// L = Latin 1
// G = Greek
// C = Cyrillic
// J = Japanese
// E = Central Europe
// T = Turkish
// B = Baltic
include ("/PATH TO LACATION OF/cp_unicode_tables.php");
$tr_ptrn = array ("/\^d/", "/\^s/", "/\^c/", "/\^a/", "/\^q/", "/\^t/", "/\^l/", "/\^r/", "/\^v/", "/\^\^/", "/</");
$tr_ptrn_r = array ("\\", "/", ":", "*", "?", "\"", "<", ">", "|", "^", "<");
?>
that gives you all you need basically.
WriteColor ($hostorplayername) would convert all colors and also figure out the alternate codepage characters (basically what you want except one thing - read on)
UnWriteColor ($hostorplayername) strips all color codes and leaves the rest alone
I've left the ^d and ^s and so forth separate. You can do those with preg_replace :
preg_replace ($tr_ptrn, $tr_ptrn_r, $hostorplayername)
So in essence, to convert all special codes in a host or playername :
WriteColor (preg_replace ($tr_ptrn, $tr_ptrn_r, $hostorplayername))