I want to add emoticon functionality to my text posting area. I want to replace with in image of a wink with a smile, etc. How would i go about doing this?
I'd use the preg_replace function with search and replace arrays.
Fill the $search array with all your emoticons. Keep in mind that a lot of the characters used in emoticons are metacharacters and will have to be escaped with the backslash character.
Fill the $replace array elements with all the HTML code necessary to make the image appropriate for each emoticon show up on a web pages.
If you invoke "<input> = preg_replace ($search, $replace, <input>)", the function will search the input for each element in $search. If it finds it, it will replace it with the respective element in $replace.
Instead of including it, open the file and parse it.
Or preparse the text before writing it to the file. This might be even better -- that way the parse only has to happen once, regardless of how many times the file is served.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.