表情替换

/**
	 * 表情替换
	 *
	 * make by Administrator on 2014-7-21 上午11:53:15
	 * @param content
	 * @return
	 */
	public static String replaceEmoticon(String content){
		String basePath = SystemPropertyGetUtil.getResource("config").getString("system.url.base");
		 Pattern pattern = Pattern.compile(":([0-9]+):");
	     String replaceStr ="<img width='24' height='24' src='"+basePath+"/resources/emoticon/normal/#.gif'/>";
	     Matcher matcher = pattern.matcher(content);
	     int i=0;
	     String tmp;
	     while(matcher.find()){
		     tmp=replaceStr.replace("#", matcher.group(1));
		     content = matcher.replaceFirst(tmp);
		     matcher = pattern.matcher(content);
	     }
	     return content;
	}
//表情替换
function replaceEmoticon(content){
	var imagePath = basePath+"/resources/emoticon/normal/";
	return content.replace(/\:([0-9]*)\:/g,'<img src="'+imagePath+'$1.gif" width="24" height="24"/>');
} 

 

分享一款基于jQuery的QQ表情插件

你可能感兴趣的:(替换)