Page 1 of 1

i need help with _replace for emoticons

Posted: Thu Aug 13, 2009 10:07 am
by Hosty
I'm using the following to insert smilies into the messages in my shoutbox...
$msg = eregi_replace("\.\.fish", "<img src=\"\./emoticons/fish.gif\" alt=\"Emoticon\" border=0>",$msg);
$msg = eregi_replace("\.\.fishing", "<img src=\"\./emoticons/fishing.gif\" alt=\"Emoticon\" border=0>",$msg);
$msg = eregi_replace("\.\.fly", "<img src=\"\./emoticons/fly.gif\" alt=\"Emoticon\" border=0>",$msg);
$msg = eregi_replace("\.\.flying", "<img src=\"\./emoticons/flying.gif\" alt=\"Emoticon\" border=0>",$msg);

It works great except for one issue... if I type the smiley code for fishing "..fishing" I get the fish smiley followed by "ing". The replace is handling fish and ignoring fishing.

Yes, I could just rename my smileys, however... all my smileys (over 100) come from my chat room. The code is always two periods followed by the name (..fishing ..smiley ..rofl etc.). Everyone knows the codes and to now change the 20 or so that conflict would be a pain for the users. We all know how users hate change.

Can someone recommend what I might do to get both ..fish and ..fishing, and ..fly and ..flying, etc... to work?

Re: i need help with _replace for emoticons

Posted: Thu Aug 13, 2009 10:11 am
by neuroxik
In this case, put fishing ABOVE fish, or else it will parse FISH inside FISHing first.

Re: i need help with _replace for emoticons

Posted: Thu Aug 13, 2009 10:32 am
by Hosty
OMG who knew it would be so simple....... (not me, apparently!! :lol: )

THANK YOU THANK YOU

it just sucks working so long on a problem and overlooking such a simple answer!

Re: i need help with _replace for emoticons

Posted: Thu Aug 13, 2009 10:34 am
by neuroxik
Hosty wrote:OMG who knew it would be so simple....... (not me, apparently!! :lol: )
THANK YOU THANK YOU
it just sucks working so long on a problem and overlooking such a simple answer!
:)

Well, often, most problems I get myself getting headaches over are simple.

UPDATE: Oh, and you might want to do it with other instances such as your FLY and FLYing (same process)

Re: i need help with _replace for emoticons

Posted: Thu Aug 13, 2009 10:40 am
by pickle
Why are you using regular expressions for this, wouldn't a simple str_replace() call work? Regular expressions have relatively huge overhead compared to simple string functions.

Re: i need help with _replace for emoticons

Posted: Thu Aug 13, 2009 11:00 am
by Hosty
TY neuroxik, i did that with all 20!

pickle, thats a good question.....i got eregi by using someone else's example. will str replace() easily compensate for case-insensitive? stri?

Re: i need help with _replace for emoticons

Posted: Thu Aug 13, 2009 12:00 pm
by pickle