FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » str_replace, replace array with string AND array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
str_replace, replace array with string AND array [message #178783] Fri, 03 August 2012 05:28 Go to previous message
jwcarlton is currently offline  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?
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Is my array understanding correct?
Next Topic: Globalizing vars in class methods doesnt seem to work, var disappears after global, var is inaccessible in other methods/funcs
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 09:39:54 GMT 2024

Total time taken to generate the page: 0.05558 seconds