kid_drew Posted October 9, 2006 Share Posted October 9, 2006 Anyone know where I can find a free smiley engine to use on a website? I could write one, but I bet there's already one out there. Quote Link to comment https://forums.phpfreaks.com/topic/23391-smiley-engine/ Share on other sites More sharing options...
tomfmason Posted October 9, 2006 Share Posted October 9, 2006 I am not realy sure what you mean by smiley engine? Please explain what it is and what it does Quote Link to comment https://forums.phpfreaks.com/topic/23391-smiley-engine/#findComment-106068 Share on other sites More sharing options...
kid_drew Posted October 9, 2006 Author Share Posted October 9, 2006 Sorry, I guess that wasn't clear. I want a class that I can plug into an existing website that will parse text and pick out the tags between colons and replace with smilies. I.e., if it finds :grin: or something similar, it will replace with ;D just like this board does. I'd like to just have a list of tags and replacement images stored in my db.Or if anyone has a good tutorial for how to create a smilie engine quickly, I'd take that too.[quote author=tomfmason link=topic=110917.msg449076#msg449076 date=1160366826]I am not realy sure what you mean by smiley engine? Please explain what it is and what it does[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/23391-smiley-engine/#findComment-106075 Share on other sites More sharing options...
Daniel0 Posted October 9, 2006 Share Posted October 9, 2006 Try something like this (I haven't tested it):[code]<?php$smileys = array( 'smile' => ':)', 'smiley2' => ':D', );foreach($smileys as $image => $code){ $images[] = "<img src='smileys/{$image}.gif' alt='{$code}' />";}$text = str_replace($smileys,$images,$text);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23391-smiley-engine/#findComment-106095 Share on other sites More sharing options...
Jeremysr Posted October 9, 2006 Share Posted October 9, 2006 Just use:str_replace( ":grin:", "<img src='grin.png' />", $message_content )That will replace :grin: with an image (a smilie) everytime it finds it in the $message_content. You could use an array or something to store the smilie information and go through a for loop to replace them with image smilies. Quote Link to comment https://forums.phpfreaks.com/topic/23391-smiley-engine/#findComment-106096 Share on other sites More sharing options...
tomfmason Posted October 9, 2006 Share Posted October 9, 2006 ^LOL you all beat me to it... I realy need to learn to type faster..lolYea that would be a bbcode. Here is a simple one[code=php:0]function addSmiles($text) { $pattern = array('=)', ':grin', ':somethingelse'); $replacements = array('<img src="path/to/yourimage">', '<img src="yourimage">', '<img src="image">'); $bbcode = str_replace($pattern, $replacements, $text); return $bbcode;}$text = $_POST['text'];$newText = addSmiles($text);echo $newText;[/code]Like I said this is simple. I wrote this one the fly so let me know if there are any errors that come up.hope that helps,Tom Quote Link to comment https://forums.phpfreaks.com/topic/23391-smiley-engine/#findComment-106113 Share on other sites More sharing options...
xsist10 Posted October 9, 2006 Share Posted October 9, 2006 If you google code phpBB or phpNuke you'll find that they use a pretty nifty regex pattern replace to handly their smileys. Quote Link to comment https://forums.phpfreaks.com/topic/23391-smiley-engine/#findComment-106136 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.