i need help with _replace for emoticons

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Hosty
Forum Newbie
Posts: 8
Joined: Wed Sep 10, 2008 8:54 am

i need help with _replace for emoticons

Post 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?
User avatar
neuroxik
Forum Commoner
Posts: 25
Joined: Tue Aug 11, 2009 10:32 pm

Re: i need help with _replace for emoticons

Post by neuroxik »

In this case, put fishing ABOVE fish, or else it will parse FISH inside FISHing first.
User avatar
Hosty
Forum Newbie
Posts: 8
Joined: Wed Sep 10, 2008 8:54 am

Re: i need help with _replace for emoticons

Post 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!
User avatar
neuroxik
Forum Commoner
Posts: 25
Joined: Tue Aug 11, 2009 10:32 pm

Re: i need help with _replace for emoticons

Post 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)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: i need help with _replace for emoticons

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Hosty
Forum Newbie
Posts: 8
Joined: Wed Sep 10, 2008 8:54 am

Re: i need help with _replace for emoticons

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: i need help with _replace for emoticons

Post by pickle »

Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply