str_replace not working on database return

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 &sect then a number specifying the color. I'm trying to use str_replace to turn the &sectnumber 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("&sect0","</span><span style=\"color:#000\">", $motd); $motd = str_replace("&sect1","</span><span style=\"color:#00A\">", $motd); $motd = str_replace("&sect2","</span><span style=\"color:#0A0\">", $motd); $motd = str_replace("&sect3","</span><span style=\"color:#0AA\">", $motd); $motd = str_replace("&sect4","</span><span style=\"color:#A00\">", $motd); $motd = str_replace("&sect5","</span><span style=\"color:#A0A\">", $motd); $motd = str_replace("&sect6","</span><span style=\"color:#FA0\">", $motd); $motd = str_replace("&sect7","</span><span style=\"color:#AAA\">", $motd); $motd = str_replace("&sect8","</span><span style=\"color:#555\">", $motd); $motd = str_replace("&sect9","</span><span style=\"color:#55F\">", $motd); $motd = str_replace("&secta","</span><span style=\"color:#5F5\">", $motd); $motd = str_replace("&sectb","</span><span style=\"color:#5FF\">", $motd); $motd = str_replace("&sectc","</span><span style=\"color:#F55\">", $motd); $motd = str_replace("&sectd","</span><span style=\"color:#F5F\">", $motd); $motd = str_replace("&secte","</span><span style=\"color:#FF5\">", $motd); $motd = str_replace("&sectf","</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 = "&sectcWelcome to &sectbSkyBlock&sectc!"\[/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.
 
Back
Top