View Full Version : Smilies


Tracey
06-04-2006, 12:13 AM
I'm looking for a script, that would allow me to use smilies on my site. For example, if I put : ) (without spaces) a :) would show up. Know anywhere I can get a code for that? I would like it in either PHp or Javascript. Please and thanks.

Douglas
06-04-2006, 12:19 AM
<?php
$text=":)";
$pattern[]="/(?<=.\W|\W.|^\W)" . preg_quote(":)", "/") . "(?=.\W|\W.|\W$)/";
$replace[]="<img src=\"images/smile.gif" border=\"0\" />";
$text=preg_replace($pattern,$replace,$text);
?>

That should work ;D

EDIT: Replace the :)'s with the text. ;D

Tracey
06-04-2006, 12:34 AM
Okay. Thanks. But what if I want multiple smiles, would I just do the same thing over? Thanks.

Douglas
06-04-2006, 12:37 AM
Just add a new:

$pattern[]="/(?<=.\W|\W.|^\W)" . preg_quote("PATTERN_HERE", "/") . "(?=.\W|\W.|\W$)/";
$replace[]="<img src=\"images/IMAGE HERE.gif" border=\"0\" />";

for each smilie ;D

Tracey
06-05-2006, 08:26 PM
Okay thanks, but for some reason it says:
Parse error: parse error, unexpected T_STRING in /home/.../public_html/smilies.php on line 4

Line four is:$replace[]="<img src=\"/cutenews/data/emoticons/smile.gif" border=\"0\" />";

Douglas
06-05-2006, 08:33 PM
$replace[]="<img src=\"/cutenews/data/emoticons/smile.gif\" border=\"0\" />";

You forgot two \'s by the two "'s