str_replace, replace array with string AND array [message #178783] |
Fri, 03 August 2012 05:28 |
jwcarlton
Messages: 76 Registered: December 2010
Karma:
|
Member |
|
|
I'm doing this:
$emArr = array(
":-)",
":-D",
":-(",
":-o",
":-x",
":-P",
":-?",
"8-)"
);
$imgArr = array(
"<img src=\"$image_path/emoticons/AddEmoticons08021.gif\">",
"<img src=\"$image_path/emoticons/AddEmoticons08047.gif\">",
"<img src=\"$image_path/emoticons/AddEmoticons08017.gif\">",
"<img src=\"$image_path/emoticons/AddEmoticons08027.gif\">",
"<img src=\"$image_path/emoticons/AddEmoticons08042.gif\">",
"<img src=\"$image_path/emoticons/AddEmoticons08050.gif\">",
"<img src=\"$image_path/emoticons/AddEmoticons08044.gif\">",
"<img src=\"$image_path/emoticons/AddEmoticons08046.gif\">"
);
$this_comment = str_replace($emArr, $imgArr, $this_comment);
Just because it would save a few bytes and be easier to read, I would like to change $imgArr to just this:
$imgArr = array(
"AddEmoticons08021.gif",
"AddEmoticons08047.gif",
"AddEmoticons08017.gif",
"AddEmoticons08027.gif",
"AddEmoticons08042.gif",
"AddEmoticons08050.gif",
"AddEmoticons08044.gif",
"AddEmoticons08046.gif"
);
and then change the str_replace to something like this:
$this_comment = str_replace($emArr,
"<img src=\"$image_path/emoticons/" . $imgArr . "\">",
$this_comment);
I tried it, of course, but instead of replacing with the correct value of $imgArr, it just replaced with "Array".
Is there a better function for this, or should I stick with the repeated text in the array?
|
|
|