Jump to content


Photo

Smiley engine


  • Please log in to reply
6 replies to this topic

#1 kid_drew

kid_drew
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 09 October 2006 - 04:05 AM

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.


#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 09 October 2006 - 04:07 AM

I am not realy sure what you mean by smiley engine? Please explain what it is and what it does

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 kid_drew

kid_drew
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 09 October 2006 - 04:57 AM

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.

I am not realy sure what you mean by smiley engine? Please explain what it is and what it does



#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 09 October 2006 - 05:48 AM

Try something like this (I haven't tested it):

<?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);
?>


#5 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 09 October 2006 - 05:49 AM

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.

#6 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 09 October 2006 - 06:00 AM

^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

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;

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

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#7 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 09 October 2006 - 08:16 AM

If you google code phpBB or phpNuke you'll find that they use a pretty nifty regex pattern replace to handly their smileys.
SA PHP Archives - www.phparchives.za.org




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users