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 &sect number specifying color. i'm trying use str_replace turn &sectnumber html element actual color. came following 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>     "; } 

however, none of str_replace functions doing anything. weird thing when replace

$motd = $server_data['motd']; 

with

$motd = "&sectcwelcome &sectbskyblock&sectc!" 

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 & , &amp; - http://codepad.viper-7.com/12phow

with this, you'll want add stylesheet

.sect0 { color: #000; } .sect1 { color: #00a; } .sect2 { color: #0a0; } /* etc */ 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -