str_replace using an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    str_replace using an array

    I am just finishing off a really basic chat system and I am having problems with a function I have made:
    Code:
    function smiley($text) {
        $smilies = array(
    	    ':)' => "<img src='emotions/happy.gif' />",
    	    ':D' => "<img src='emotions/vhappy.gif' />",
    	    ':(' => "<img src='emotions/sad.gif' />",
    	    ';)' => "<img src='emotions/winking.gif' />",
    	    '>)' => "<img src='emotions/evil.gif' />",
    	    '>(' => "<img src='emotions/mad.gif' />",
        );
        $text = str_replace( array_keys($smilies), array_values($smilies), $text );
        return $text;
    }
    It simply does not work. There is no change to the $test value. Does anyone know why?
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Sorry for the post. Figured it out. That bit does work, it was another problem but fixed that and it works. Apologies again.

    Comment

    Working...