非常简单的UBB代码
效果图:

<meta http-equiv="content-type" content="text/html;charset=utf8">
<?php
function getUbb($subject){
$subject=preg_replace("/(\[)o_a(.*)(\])/iU", "<img src=\"http://images.cnblogs.com/cnblogs_com/perseverancevictory/570190/o_a\\2.gif\"/>", $subject);//正则替换
$subject=preg_replace("/\[b\](.*)\[\/b\]/iU", "<b>\\1</b>", $subject);
$subject=preg_replace("/\[url\](.*)\[\/url\]/iU", "<a href=\"\\1\">\\1</a>", $subject);
return $subject;
}
if ($_POST['sub']) {
echo getUbb($_POST['text']);
# code...
}
?>
<hr>
<script>
function inserttag(open,close){
var text=document.getElementById('content');
text.focus();
var s1=text.value;
text.value =s1+open+close;
return;
}
</script>
<img src="http://images.cnblogs.com/cnblogs_com/perseverancevictory/570190/o_a1.gif" width="45" style="cursor:hand" onclick='inserttag("[o_a1","]");'>
<img src="http://images.cnblogs.com/cnblogs_com/perseverancevictory/570190/o_a2.gif" width="45" style="cursor:hand" onclick='inserttag("[o_a2","]");'>
<img src="http://images.cnblogs.com/cnblogs_com/perseverancevictory/570190/o_a3.gif" width="45" style="cursor:hand" onclick='inserttag("[o_a3","]");'>
<img src="http://images.cnblogs.com/cnblogs_com/perseverancevictory/570190/o_a4.gif" width="45" style="cursor:hand" onclick='inserttag("[o_a4","]");'>
<img src="http://images.cnblogs.com/cnblogs_com/perseverancevictory/570190/o_a5.gif" width="45" style="cursor:hand" onclick='inserttag("[o_a5","]");'>
<img src="http://images.cnblogs.com/cnblogs_com/perseverancevictory/570190/o_a6.gif" width="45" style="cursor:hand" onclick='inserttag("[o_a6","]");'>
<a href="javascript:void(0);" onclick='inserttag("[b]","[/b]");'>加粗</a>
<a href="javascript:void(0);" onclick='inserttag("[url]http://","[/url]");'>超链接</a>
<form action="" method="post">
<textarea name="text" id="content" cols="40" rows="10"></textarea>
<input type="submit" name="sub" style="cursor:hand" value="提交">
</form>

浙公网安备 33010602011771号