Call of Duty and Quake Games uses Codes form ^0 to ^1 to define colour in Names (Strings). I'm working on a custom Web RCON Script and having issues replacing the ^0 ~ ^9 with HTML Colors for output
Im Trying to Replace e.g the following in PHP
the string is generated and looks similar to Lets Say eg.
^3THE^7::^5MODERNWARFARE^7::^3Server
Im using 2 arrays for this
$find = array(
'/\^0(.*?)\^/',
'/\^1(.*?)\^/',
'/\^2(.*?)\^/',
'/\^3(.*?)\^/',
'/\^4(.*?)\^/',
'/\^5(.*?)\^/',
'/\^6(.*?)\^/',
'/\^7(.*?)\^/',
'/\^8(.*?)\^/',
'/\^9(.*?)\^/',
);
$replace = array(
'<font color="#000000">$1</font>^',
'<font color="#F65A5A">$1</font>^',
'<font color="#00F100">$1</font>^',
'<font color="#EFEE04">$1</font>^',
'<font color="#0F04E8">$1</font>^',
'<font color="#04E8E7">$1</font>^',
'<font color="#F75AF6">$1</font>^',
'<font color="#FFFFFF">$1</font>^',
'<font color="#7E7E7E">$1</font>^',
'<font color="#6E3C3C">$1</font>^',
);
// Just a Random Test String
$aDemoString = "^3THE^7::^5MODERNWARFARE^7::^3Server^7";
$namefix = preg_replace($find, $replace, $aDemoString);
echo $namefix;
The Output only partially works, and i get
<font color="#00F100">THE</font><font color="#FFFFFF">::<font color="#04E8E7">MODERNWARFARE</font></font>^7::<font color="#00F100">Server</font>^7
and it breaks the closing </font>
tag
if i remove a ^7 to the end of the string i get
<font color="#00F100">THE</font><font color="#FFFFFF">::<font color="#04E8E7">MODERNWARFARE</font></font>^7::^2Server
It doesnt appear to replace the ^7 in the string correctly and for some reason messes up the html </font>
end tag also if i remove the last ^7 then it breaks the last "^2" replacement
My Question is How Do I get PHP Preg_replace to do this correctly, any Help ?
instead of ^ you can replace like this
The patern is ^0STRING^ so you should remove the number at the end, to make all of the parts 'work' (and have the same patern).
So first you should do this:
That is part one, then you should make sure that the ^-character isn't included in the replacing:
Try this: