A better way to replace emoticons in PHP?

后端 未结 5 1541
忘掉有多难
忘掉有多难 2020-12-05 21:40

Right now I am using this function for emoticons:

function emoticons($text) {
        $icons = array(
                \':)\'    =>  \'

        
5条回答
  •  星月不相逢
    2020-12-05 22:04

    I'm not sure whether it will work or not, but I'd try to put some extra spaces like this:

    function emoticons($text) {
        $icons = array(
                ' :) '    =>  ' smile ',
                ' :-) '   =>  ' smile ',
                ' :D '    =>  ' smile ',
                ' :d '    =>  ' laugh ',
                ' ;) '    =>  ' wink ',
                ' :P '    =>  ' tounge ',
                ' :-P '   =>  ' tounge ',
                ' :-p '   =>  ' tounge ',
                ' :p '    =>  ' tounge ',
                ' :( '    =>  ' sad face ',
                ' :o '    =>  ' shock ',
                ' :O '    =>  ' shock ',
                ' :0 '    =>  ' shock ',
                ' :| '    =>  ' straight face ',
                ' :-| '   =>  ' straight face ',
                ' :/ '    =>  ' straight face ',
                ' :-/ '   =>  ' straight face '
        );
        return strtr($text, $icons);
    }
    

提交回复
热议问题