求一正则表达式,替换某一规则的表情符号为表情图标(<img>表情) $str='[高兴]表情图片';echo preg_replace('/\[(.*)\]/',"<img src='images/$1.png'/>",$str); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 PhpNewnew 于 2012-04-30 10:57:09 编辑 我在网上找到一个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)); });} 注意看看有木有错误提示alert(str );看看是否替换了。估计是图片名称是中文名称的原因。改用英文吧 那个JQ插件是用0.png、1.png、2.png来替换[face]的但是把face换成中文就不行了,真奇怪 批量替换某表里面某个字段的关键字,sql应该怎么写 飞行数据回放、高分请大虾帮忙指点 php中利用DOM解析xml文件 出现的问题 请教大家啊 有点急 php怎么把内容输出到apache的日志中? phpMyAdmin安装问题? 请教一个随机显示图片的代码!! 明天要去面试了,请教各位大大一些问题,小弟感激不尽~~~~~~~ Redhat linux 8下让PHP支持java类 的求助 我的本地配置出现了什么问题? 那里能找到比较好的php的下载站点: PHP的弱智问题 怎么使在网页上点击退出登录后,清除session呢?求教!
// 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));
});
}
看看是否替换了。
估计是图片名称是中文名称的原因。改用英文吧
但是把face换成中文就不行了,真奇怪