php难题(添加表情)
2个回答
展开全部
<?php
function get_ubb($str) {
$str = preg_replace("/(\[)em(.*?)(\])/i", "<img src=\"em/\\2.gif\" />", $str);
return $str;
}
if($_POST['sub']){
echo get_ubb($_POST[message]);
}
?>
<script>
function inserttag(topen,tclose){
var themess = document.getElementById('con');//编辑对象
themess.focus();
if (document.selection) {//如果是否ie浏览器
var theSelection = document.selection.createRange().text;//获取选区文字
//alert(theSelection);
if(theSelection){
document.selection.createRange().text = theSelection = topen+theSelection+tclose;//替换
}else{
document.selection.createRange().text = topen+tclose;
}
theSelection='';
}else{//其他浏览器
var scrollPos = themess.scrollTop;
var selLength = themess.textLength;
var selStart = themess.selectionStart;//选区起始点索引,未选择为0
var selEnd = themess.selectionEnd;//选区终点点索引
if (selEnd <= 2)
selEnd = selLength;
var s1 = (themess.value).substring(0,selStart);//截取起始点前部分字符
var s2 = (themess.value).substring(selStart, selEnd)//截取选择部分字符
var s3 = (themess.value).substring(selEnd, selLength);//截取终点后部分字符
themess.value = s1 + topen + s2 + tclose + s3;//替换
themess.focus();
themess.selectionStart = newStart;
themess.selectionEnd = newStart;
themess.scrollTop = scrollPos;
return;
}
}
</script>
<hr/>
<font size=2>
<img src="em/0.gif" onclick='inserttag("[em0","]");' />
<img src="em/1.gif" onclick='inserttag("[em1","]");' />
<img src="em/2.gif" onclick='inserttag("[em2","]");' />
<img src="em/3.gif" onclick='inserttag("[em3","]");' />
<img src="em/4.gif" onclick='inserttag("[em4","]");' />
<img src="em/5.gif" onclick='inserttag("[em5","]");' />
<img src="em/6.gif" onclick='inserttag("[em6","]");' />
<img src="em/7.gif" onclick='inserttag("[em7","]");' />
<img src="em/8.gif" onclick='inserttag("[em8","]");' />
<img src="em/9.gif" onclick='inserttag("[em9","]");' />
<form action="" method="post">
<textarea name="message" id="con" cols="70%" rows="10"></textarea><br>
<input type="submit" name="sub" value="提交"/>
</form>
表情放在em文件夹下面
QQ:706561147
function get_ubb($str) {
$str = preg_replace("/(\[)em(.*?)(\])/i", "<img src=\"em/\\2.gif\" />", $str);
return $str;
}
if($_POST['sub']){
echo get_ubb($_POST[message]);
}
?>
<script>
function inserttag(topen,tclose){
var themess = document.getElementById('con');//编辑对象
themess.focus();
if (document.selection) {//如果是否ie浏览器
var theSelection = document.selection.createRange().text;//获取选区文字
//alert(theSelection);
if(theSelection){
document.selection.createRange().text = theSelection = topen+theSelection+tclose;//替换
}else{
document.selection.createRange().text = topen+tclose;
}
theSelection='';
}else{//其他浏览器
var scrollPos = themess.scrollTop;
var selLength = themess.textLength;
var selStart = themess.selectionStart;//选区起始点索引,未选择为0
var selEnd = themess.selectionEnd;//选区终点点索引
if (selEnd <= 2)
selEnd = selLength;
var s1 = (themess.value).substring(0,selStart);//截取起始点前部分字符
var s2 = (themess.value).substring(selStart, selEnd)//截取选择部分字符
var s3 = (themess.value).substring(selEnd, selLength);//截取终点后部分字符
themess.value = s1 + topen + s2 + tclose + s3;//替换
themess.focus();
themess.selectionStart = newStart;
themess.selectionEnd = newStart;
themess.scrollTop = scrollPos;
return;
}
}
</script>
<hr/>
<font size=2>
<img src="em/0.gif" onclick='inserttag("[em0","]");' />
<img src="em/1.gif" onclick='inserttag("[em1","]");' />
<img src="em/2.gif" onclick='inserttag("[em2","]");' />
<img src="em/3.gif" onclick='inserttag("[em3","]");' />
<img src="em/4.gif" onclick='inserttag("[em4","]");' />
<img src="em/5.gif" onclick='inserttag("[em5","]");' />
<img src="em/6.gif" onclick='inserttag("[em6","]");' />
<img src="em/7.gif" onclick='inserttag("[em7","]");' />
<img src="em/8.gif" onclick='inserttag("[em8","]");' />
<img src="em/9.gif" onclick='inserttag("[em9","]");' />
<form action="" method="post">
<textarea name="message" id="con" cols="70%" rows="10"></textarea><br>
<input type="submit" name="sub" value="提交"/>
</form>
表情放在em文件夹下面
QQ:706561147
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询