douhan9467 2011-03-07 15:10
浏览 29
已采纳

str_replace不会替换所有键?

I'm making my own forum software. Well its normal to have smileys in your forum.

So i made an array with all the smileys and putted them in a function:

function si_ubb($string){
    $smileys = array(
        '0<:)' => 'angelnot.gif',
        '>:(' => 'angry.gif',
        ':@' => 'blush.gif',
        ':*' => 'cencored.png',
        ':?' => 'confused.gif',
        ';(' => 'cry.png',
        ':D' => 'grin.gif',
        ':)' => 'happy.gif',
        ':|' => 'hmm.png',
        '0:)' => 'hypocrite.gif',
        ':x:' => 'lock.gif',
        '<3' => 'love.gif',
        '8)' => 'rolleyes.gif',
        ':(' => 'sad.png',
        '|)' => 'shifty.gif',
        'O_o' => 'shock.gif',
        '8)' => 'sunglasses.gif',
        '^_^' => 'sweatingbullets.gif',
        ':p' => 'tongue.gif',
        ':P' => 'tongue.gif',
        ';)' => 'wink.gif',
        '>.<' => 'wry.gif',
        'XD' => 'wry.gif',
        'xD' => 'wry.gif'
    );

    foreach($smileys as $code => $image){
        $string = str_replace($code, $image, $string);
    }

    return $string;
}   

But, ehm, when i do this now:

echo si_ubb('0<:)');

It gives this?

0<Image

But how? And why? Why isn't it showing the right smiley?

Greetings

  • 写回答

4条回答 默认 最新

  • douyang2530 2011-03-07 15:15
    关注

    As ck3g said, move ':)' => 'happy.gif', below '0:)' => 'hypocrite.gif',

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型