<?php<br />
function get_ubb($str) {<br />
<br />
$str = preg_replace("/(\[)em(.*?)(\])/i", "<img src=\"emot/em\\2.gif\" />", $str);<br />
//链接UBB<br />
$str = preg_replace("/(\[url\])(.*)(\[\/url\])/i", "<a href=\\2 <br />
<br />
target=\"new\">\\2</a>", $str);<br />
//QQ号码UBB<br />
$str = preg_replace("/\[qq\]([0-9]*)\[\/qq\]/i", "<a target=\"_blank\" <br />
<br />
href=\"tencent://message/?uin=\${1}&amp;site=www.php100.com&amp;menu=yes\"><img <br />
<br />
src=\"http://wpa.qq.com/pa?p=1:\${1}:8\" alt=\"QQ\${1}\" height=\"16\" border=\"0\" <br />
<br />
align=\"top\" /></a>", $str);<br />
<br />
return $str;<br />
}<br />
<br />
if($_POST['sub']){<br />
echo get_ubb($_POST[message]);<br />
}<br />
<br />
<br />
?><br />
<script><br />
function inserttag(topen,tclose){<br />
var themess = document.getElementById('con');//编辑对象<br />
themess.focus();<br />
if (document.selection) {//如果是否ie浏览器<br />
var theSelection = document.selection.createRange().text;//获取选区文字<br />
//alert(theSelection);<br />
if(theSelection){<br />
document.selection.createRange().text = theSelection = topen+theSelection+tclose;//替<br />
<br />
换<br />
}else{<br />
document.selection.createRange().text = topen+tclose;<br />
}<br />
theSelection='';<br />
<br />
}else{//其他浏览器<br />
<br />
var scrollPos = themess.scrollTop;<br />
var selLength = themess.textLength;<br />
var selStart = themess.selectionStart;//选区起始点索引,未选择为0<br />
var selEnd = themess.selectionEnd;//选区终点点索引<br />
if (selEnd <= 2)<br />
selEnd = selLength;<br />
<br />
var s1 = (themess.value).substring(0,selStart);//截取起始点前部分字符<br />
var s2 = (themess.value).substring(selStart, selEnd)//截取选择部分字符<br />
var s3 = (themess.value).substring(selEnd, selLength);//截取终点后部分字符<br />
<br />
themess.value = s1 + topen + s2 + tclose + s3;//替换<br />
<br />
themess.focus();<br />
themess.selectionStart = newStart;<br />
themess.selectionEnd = newStart;<br />
themess.scrollTop = scrollPos;<br />
return;<br />
}<br />
}<br />
</script><br />
<hr/><br />
<font size=2><br />
<img src="emot/em_01.gif" onclick='inserttag("[em_01","]");' /><br />
<img src="emot/em_02.gif" onclick='inserttag("[em_02","]");' /><br />
<img src="emot/em_03.gif" onclick='inserttag("[em_03","]");' /><br />
<img src="emot/em_04.gif" onclick='inserttag("[em_04","]");' /><br />
<img src="emot/em_05.gif" onclick='inserttag("[em_05","]");' /><br />
<img src="emot/em_06.gif" onclick='inserttag("[em_06","]");' /><br />
<img src="emot/em_07.gif" onclick='inserttag("[em_07","]");' /><br />
<img src="emot/em_08.gif" onclick='inserttag("[em_08","]");' /><br />
<a href="javascript:void(0);" onclick='inserttag("<b>","</b>");'>加粗</a><br />
<a href="javascript:void(0);" onclick='inserttag("[qq]","[/qq]");'>QQ号</a><br />
<a href="javascript:void(0);" onclick='inserttag("<a href="," target="new">","</a>");'>超链接</a><br />
<br><br />
<br />
<form action="" method="post"><br />
<textarea name="message" id="con" cols="70%" rows="10"></textarea><br />
<input type="submit" name="sub" value="提交"/><br />
</form>