Jump to content

Smiley engine


kid_drew

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.