johnseastar
New Member
I'm getting stumped by what should be a really simple str_replace function.In my database, I have a field for a minecraft server motd(message of the day). When I collect data from servers I store the data including the motd in my database. Servers are able to color motds by adding a color code, which I have stored in the database as § then a number specifying the color. I'm trying to use str_replace to turn the §number into an html element with the actual color. I came up with the following code: \[code\]if ($server_data['show_motd'] == 1) { $motd = $server_data['motd']; $motd = str_replace("§0","</span><span style=\"color:#000\">", $motd); $motd = str_replace("§1","</span><span style=\"color:#00A\">", $motd); $motd = str_replace("§2","</span><span style=\"color:#0A0\">", $motd); $motd = str_replace("§3","</span><span style=\"color:#0AA\">", $motd); $motd = str_replace("§4","</span><span style=\"color:#A00\">", $motd); $motd = str_replace("§5","</span><span style=\"color:#A0A\">", $motd); $motd = str_replace("§6","</span><span style=\"color:#FA0\">", $motd); $motd = str_replace("§7","</span><span style=\"color:#AAA\">", $motd); $motd = str_replace("§8","</span><span style=\"color:#555\">", $motd); $motd = str_replace("§9","</span><span style=\"color:#55F\">", $motd); $motd = str_replace("§a","</span><span style=\"color:#5F5\">", $motd); $motd = str_replace("§b","</span><span style=\"color:#5FF\">", $motd); $motd = str_replace("§c","</span><span style=\"color:#F55\">", $motd); $motd = str_replace("§d","</span><span style=\"color:#F5F\">", $motd); $motd = str_replace("§e","</span><span style=\"color:#FF5\">", $motd); $motd = str_replace("§f","</span><span style=\"color:#FFF\">", $motd); echo " <tr> <td class=\"serverdisplayspan\">MOTD:</td> <td class=\"serverdisplaylidet\"><span>$motd</span</td> </tr> ";}\[/code\]However, none of the str_replace functions are doing anything. The weird thing is that when I replace \[code\]$motd = $server_data['motd'];\[/code\]with \[code\]$motd = "§cWelcome to §bSkyBlock§c!"\[/code\]which is what is stored in the database, it works perfectly. Without the str_replaces, the two variables look exactly the same. I've even checked the type of each variable using gettype() and both of them are strings. I've also tried utf_decode() on the database result, but nothing seems to work. Is there some difference between the database result and the string i just typed in? I can't find out what it is but there must obviously be one. Thanks.