求一正则表达式,替换某一规则的表情符号为表情图标(<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换成中文就不行了,真奇怪 需要计算的PHP验证码帮助解决 把对象做为参数传递,这种习惯好不好? 关于array_unique函数的问题 php怎么调用两个关联数据表里的数据 验证表单数据 一直有个疑问,关于密码保存的问题 用php做了网络通不通的程序不好用?有问题? php中有没有在FTP服务器上直接新建文件并写入的函数? 如何使从mysql中查找的字串不区分大小写? 怎么解决win8系统安装zend权限不足的问题 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换成中文就不行了,真奇怪