代码如下:
<?php
function get_ubb($str) {
$str = preg_replace("/(\[)em(.*?)(\])/i", "<img src=\"pic/em\\2.gif\" />", $str);
//链接UBB
$str = preg_replace("/(\[url\])(.*)(\[\/url\])/i", "<a href=\\2 target=\"new\">\\2</a>", $str);
//QQ号码UBB
$str = preg_replace("/\[qq\]([0-9]*)\[\/qq\]/i", "<a target=\"_blank\" href=\"tencent://message/?uin=\${1}&site=www.php100.com&menu=yes\"><img src=\"http://wpa.qq.com/pa?p=1:\${1}:8\" alt=\"QQ\${1}\" height=\"16\" border=\"0\" align=\"top\" /></a>", $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="/pic/em_01.gif" onclick='inserttag("[em_01","]");' />
<img src="/pic/em_02.gif" onclick='inserttag("[em_02","]");' />
<img src="/pic/em_05.gif" onclick='inserttag("[em_05","]");' />
<img src="/pic/em_06.gif" onclick='inserttag("[em_06","]");' />
<img src="/pic/em_07.gif" onclick='inserttag("[em_07","]");' />
<a href="javascript:void(0);" onclick='inserttag("","");'>加粗</a>
<a href="javascript:void(0);" onclick='inserttag("[qq]","[/qq]");'>QQ号</a>
<a href="javascript:void(0);" onclick='inserttag("[url]","");'>超链接</a>
<form action="" method="post">
<textarea name="message" id="con" cols="70%" rows="10">
(本帖被作者修改过2次,最后一次修改时间2009-08-06 20:32:28) |