Jump to content

Archived

This topic is now archived and is closed to further replies.

kid_drew

Smiley engine

Recommended Posts

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.

Share this post


Link to post
Share on other sites
I am not realy sure what you mean by smiley engine? Please explain what it is and what it does

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
^LOL you all beat me to it... I realy need to learn to type faster..lol

Yea 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

Share this post


Link to post
Share on other sites
If you google code phpBB or phpNuke you'll find that they use a pretty nifty regex pattern replace to handly their smileys.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.