插件59:改变表情符号

<?php // Plug-in 59: Replace Smileys
/*
 * 插件说明:
 * 插件接受一个字符串,查找它的情感图标,并把它替换为FIG表情符。
 * 这需要以下参数:
 * $text 代表感情的图标文本。
 * $folder 保存GIF表情符的文件夹。
 */
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$text = <<<_END
<table width='100%' border='0'><tr><td><pre><center>
angry >:(
blank :|
blush :X
cool  B-)
</center></pre></td><td><pre><center>
cry   :-(
dizzy *-*
happy :-)
kiss  =*
</center></pre></td><td><pre><center>
laugh   :D
puzzled O.o
sad     :(
shocked :o
</center></pre></td><td><pre><center>
sleep  I-)
smiley :)
sneaky :->
tongue :p
</center></pre></td><td><pre><center>
uhoh    =-o
uneasy  :/
wideeye 8)
wink    ;)
</center></pre></td></tr></table>
_END;

echo PIPHP_ReplaceSmileys($text, 'smileys/');

function PIPHP_ReplaceSmileys($text, $folder)
{
   // Plug-in 59: Replace Smileys
   //
   // This plug-in replaces any smiley emoticons in a string
   // with HTML refrring to animated GIFs. The arguments
   // required are:
   //
   //    $text:   The text to process
   //    $folder: Folder containing the smiley GIFs
   //
   // The Download link on the website includes a folder of
   // 20 smiley GIFs which will work with this plug-in, as
   // long as you do not rename them.

   $chars = array('>:-(', '>:(', 'X-(',  'X(',
                  ':-)*', ':)*', ':-*',  ':*', '=*',
                  ':)',   ':]',
                  ':-)',  ':-]',
                  ':(',   ':C',   ':[',
                  ':-(',  ':\'(', ':_(',
                  ':O',   ':-O',
                  ':P',   ':b',   ':-P', ':-b',
                  ':D',   'XD',
                  ';)',   ';-)',
                  ':/',   ':\\',  ':-/', ':-\\',
                  ':|',
                  'B-)',  'B)',
                  'I-)',  'I)',
                  ':->',  ':>',
                  ':X',   ':-X',
                  '8)',   '8-)',
                  '=-O',  '=O',
                  'O.o',  ':S',   ':-S',
                  '*-*',  '*_*');

   $gifs = array( 'angry',   'angry',   'angry',  'angry',
                  'kiss',    'kiss',    'kiss',   'kiss', 'kiss',
                  'smiley',  'smiley',
                  'happy',   'happy',
                  'sad',     'sad',     'sad',
                  'cry',     'cry',     'cry',
                  'shocked', 'shocked',
                  'tongue',  'tongue',  'tongue', 'tongue',
                  'laugh',   'laugh',
                  'wink',    'wink',
                  'uneasy',  'uneasy',  'uneasy', 'uneasy',
                  'blank',
                  'cool',    'cool',
                  'sleep',   'sleep',
                  'sneaky',  'sneaky',
                  'blush',   'blush',
                  'wideeye', 'wideeye',
                  'uhoh',    'uhoh',
                  'puzzled', 'puzzled', 'puzzled',
                  'dizzy',   'dizzy');

   if (substr($folder, -1) == '/')
      $folder = substr($folder, 0, -1);

   for ($j = 0 ; $j < count($gifs) ; ++$j)
      $gifs[$j] = "<image src='$folder/$gifs[$j].gif' " .
         "width='15' height='15' border='0' alt='$gifs[$j]' " .
         "title='$gifs[$j]' />";

   return str_ireplace($chars, $gifs, $text);
}

?>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值