i have prefixe for groupnames in a database, they consist of normal text and color codes eg.: &c[&aAdmin&c]. The colorcodes start with an & and then one character or a number. they end on the next colorcode or the end of the string. There are no & as text in the string. For now i have this function, but it only can handle one colorcode at the beginning of the string. any suggestions for a nice regex replace to handle multiple colorcodes in one string?
function mccolor($string){
$codes = array( "&0",
"&1",
"&2",
"&3",
"&4",
"&5",
"&6",
"&7",
"&8",
"&9",
"&a",
"&b",
"&c",
"&d",
"&e",
"&f");
$replace = array(
'<span style="color:#000000;">',
'<span style="color:#0000BF;">',
'<span style="color:#00BF00;">',
'<span style="color:#00BFBF;">',
'<span style="color:#BF0000;">',
'<span style="color:#BF00BF;">',
'<span style="color:#BFBF00;">',
'<span style="color:#BFBFBF;">',
'<span style="color:#404040;">',
'<span style="color:#4040FF;">',
'<span style="color:#40FF40;">',
'<span style="color:#40FFFF;">',
'<span style="color:#FF4040;">',
'<span style="color:#FF40FF;">',
'<span style="color:#3F3F10;">',
'<span style="color:#FFFFFF;">');
return str_replace($codes, $replace, $string).'</span>';
}