Page 1 of 1
Checking for smilies in a text area and changing them...
Posted: Mon Jul 12, 2004 9:50 pm
by jonas
I'm working on the forums area of my site now and I want to make a bunch of smilies for users to use.
The text area that they write their message in (like this one) should be checked for say a : + ) and replace it with a

but only if it is on it's on. Not if its in a word or something.
Anyways, I need some help on the best way to do this and to make it automated as well.
Say the admins can put a new smilie in the backend with a command and it would automatically update posts and new posts.
Thanks
Posted: Mon Jul 12, 2004 11:40 pm
by PrObLeM
str_replace()
http://us4.php.net/str_replace
Code: Select all
$string = str_replace(':)', '<img src="http://forums.devnetwork.net/images/smiles/icon_smile.gif">', $string);
Posted: Tue Jul 13, 2004 8:45 am
by Buddha443556
I'm inserting smilies as bbcode img's. Avoids problems like those in the above post with the smiley showing up in a php code section. No need to turn smilies on or off either.
Posted: Tue Jul 13, 2004 9:43 am
by kettle_drum
To avoid the problem above you just need to use a better regex to find out of its really a smilly:
(humm:-) = NO
(humm

) = OK
words[space][smile][space]words = OK
Posted: Tue Jul 13, 2004 11:00 am
by Buddha443556
To avoid the problem above you just need to use a better regex to find out of its really a smilly
Even with perfect regular expressions there's still human error. I'm also not saying my way is any better either. Every choice has it's pro's and con's. One big drawback of my method is increased data.
:-) = 3 bytes
[ img][ /img] = 11+ bytes
It avoids second guessing the user but at a cost.
Posted: Tue Jul 13, 2004 11:02 am
by kettle_drum
Or you go for something that people are less likely to make mistakes in printing like [smile] [laugh] [sulk] [cry], as long as you have a key to show users how to use them, or some javascript to add them then its all good.
Posted: Wed Jul 14, 2004 11:33 am
by jonas
Ok that's cool but say I wanted to make a backend for it and have it so it automatically updates without me having to insert a new line of code,.......
I guess I could insert a table in the DB that holds the smilies and their URLs/activate code and in the query while, do the check with variables.
Then if I add one into the database via a backend it would work automatically.
I guess you can ignore this, I seem to have talked through the solution myself.

haha