php - str_replace not working on database return -
i'm getting stumped should simple str_replace function. in database, have field minecraft server motd(message of day). when collect data servers store data including motd in database.
servers able color motds adding color code, have stored in database § number specifying color. i'm trying use str_replace turn §number html element actual color. came following 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> "; }
however, none of str_replace functions doing anything. weird thing when replace
$motd = $server_data['motd'];
with
$motd = "§cwelcome §bskyblock§c!"
which stored in database, works perfectly. without str_replaces, 2 variables same. i've checked type of each variable using gettype() , both of them strings. i've tried utf_decode() on database result, nothing seems work.
is there difference between database result , string typed in? can't find out there must one.
thanks.
how (swaps out inline styles css classes)
$motd = preg_replace('/&(amp;)?(sect[0-9a-f])/', '</span><span class="$2">', $motd);
quick demo here mixed &
, &
- http://codepad.viper-7.com/12phow
with this, you'll want add stylesheet
.sect0 { color: #000; } .sect1 { color: #00a; } .sect2 { color: #0a0; } /* etc */
Comments
Post a Comment