$str='[高兴]表情图片';
echo preg_replace('/\[(.*)\]/',"<img src='images/$1.png'/>",$str);

解决方案 »

  1.   

    本帖最后由 PhpNewnew 于 2012-04-30 10:57:09 编辑
      

  2.   

    我在网上找到一个JQ插件,在客户端进行替换的,对于[happy]这类的英文表情符号可以替换,但是一旦换到[高兴]中文表情符号就不行,嗯嗯,我也感觉用中文做文件名不好。
    // jQuery Plugins: On/Off Emtions 
    var __emotion__cache = false;
    jQuery.fn.emotions = function() {
        var aEmotion = new Array();
        
        aEmotion[21] = new Array('[happy]','\\[happy\\]');
        
        __emotion__cache = true;
        this.each(function() {
            str = $(this).html();
            for(iEM in aEmotion){
                reg =  new RegExp(aEmotion[iEM][1],"ig");
                str = str.replace(reg,'<span class="plugin_emotion" title="'+encodeURIComponent(aEmotion[iEM][0])+'"><img  src="emotions/'+iEM+'.gif" /></span>');
            }
            $(this).html(str);
        });
    };
    jQuery.fn.unemotions = function(){
        __emotion__cache = false;
        $('.plugin_emotion').each(function(){
            $(this).html(decodeURIComponent(this.title));                                   
        });
    }
      

  3.   

    注意看看有木有错误提示alert(str );
    看看是否替换了。
    估计是图片名称是中文名称的原因。改用英文吧
      

  4.   

    那个JQ插件是用0.png、1.png、2.png来替换[face]的
    但是把face换成中文就不行了,真奇怪