Topic: How would you go about on doing this? (str_replace related)

I want to have multiple emoticons to represent an image, such as sad and :'( all linked to sad.png. This is what I've tried:

<?php
$array1 = array(':)', ':D', array(':(', ':/'));
$array2 = array('happy', 'exicited', 'sad');
echo str_replace($array1, $array2, ':) :D :( :/');

//happy exicited :( :/
?>

It doesn't output what I want (happy excited sad sad). Is this because str_replace doesn't handle multi-dimensional arrays? If so, what is the most efficient way of doing this? Just replicating the value? (i.e $array2 = array('happy', 'exicited', 'sad', 'sad');)

Re: How would you go about on doing this? (str_replace related)

orlandu63 wrote:

Is this because str_replace doesn't handle multi-dimensional arrays? If so, what is the most efficient way of doing this? Just replicating the value? (i.e $array2 = array('happy', 'exicited', 'sad', 'sad');)

I believe that is correct.

Re: How would you go about on doing this? (str_replace related)

Yep, correct indeed.

<?php
$arr1 = array(':)', ':D', ':(', ':/');
$arr2 = array('happy', 'excited', 'sad', 'sad');
echo str_replace($arr1, $arr2, $text);
?>