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
Re: str_replace, replace array with string AND array [message #178790 is a reply to message #178784] Sat, 04 August 2012 02:38 Go to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma:
Member
On Friday, August 3, 2012 2:29:32 AM UTC-4, Erwin Moller wrote:
> You could try to do it like this:
>
> (I added the arrays together)
>
> $prefix = '<img src="$image_path/emoticons/';
> $postfix = '">';
>
> $emArr = array(
> ":-)" => $prefix."AddEmoticons08021.gif".$postfix,
> ":-D" => $prefix."AddEmoticons08047.gif".$postfix,
> ":-(" => $prefix."AddEmoticons08017.gif.$postfix
> // etc. etc.
> );
>
> And then
>
> $this_comment = str_replace
> (array_keys($emArr), $emArr, $this_comment);


That works, thanks! And especially thanks for the tip on using the hash array; I didn't think about using array_keys(). That's much easier to read!
[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: Sun Nov 10 12:04:47 GMT 2024

Total time taken to generate the page: 0.04606 seconds