加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何在PHP代码中插入表情符号?

发布时间:2020-12-13 22:19:36 所属栏目:PHP教程 来源:网络整理
导读:我有一个用 PHP语言编写的Shoutout Box.它没有Smileys支持.如何在其中插入笑脸支持? 解决方法 一些PHP在当天为我工作;) function Smilify($subject){ $smilies = array( ':|' = 'mellow',':-|' = 'mellow',':-o' = 'ohmy',':-O' = 'ohmy',':o' = 'ohmy',':O
我有一个用 PHP语言编写的Shoutout Box.它没有Smileys支持.如何在其中插入笑脸支持?

解决方法

一些PHP在当天为我工作;)

function Smilify(&$subject)
{
    $smilies = array(
        ':|'  => 'mellow',':-|' => 'mellow',':-o' => 'ohmy',':-O' => 'ohmy',':o'  => 'ohmy',':O'  => 'ohmy',';)'  => 'wink',';-)' => 'wink',':p'  => 'tongue',':-p' => 'tongue',':P'  => 'tongue',':-P' => 'tongue',':D'  => 'biggrin',':-D' => 'biggrin','8)'  => 'cool','8-)' => 'cool',':)'  => 'smile',':-)' => 'smile',':('  => 'sad',':-(' => 'sad',);

    $sizes = array(
        'biggrin' => 18,'cool' => 20,'haha' => 20,'mellow' => 20,'ohmy' => 20,'sad' => 20,'smile' => 18,'tongue' => 20,'wink' => 20,);

    $replace = array();
    foreach ($smilies as $smiley => $imgName)
    {
        $size = $sizes[$imgName];
        array_push($replace,'<img src="imgs/'.$imgName.'.gif" alt="'.$smiley.'" width="'.$size.'" height="'.$size.'" />');
    }
    $subject = str_replace(array_keys($smilies),$replace,$subject);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读