luobo2ni 发表于 2018-12-24 09:58:04

php创建属于自己的UBB代码

  实际上,在php中,ubb代码是html的一种变种,它的全称是Ultimate Bullrtin Board.例子如下:
  www.运维网.com
  php学习
  ../image/demo.swf
  它的优点是,实现一些我们基本常用的一些功能,使用起来也更加便利,而且相对html安全性更高一些,同时呢,也有效的减少了数据库存储代码,它的缺点是排版功能比较弱,同时也不允许标签之间的交叉嵌套使用。
  它的运行过程有两种模式,ubb->db->解析->输出;ubb->解析->db->输出,其中前者更为规范一些。
  下面就是实例。
  新建一个test工程 ,新建一个ubb.php:
  function get_ubb($str) {
  

  $str = preg_replace("/(\[)em(.*?)(\])/i", "", $str);
  //链接UBB
  $str = preg_replace("/(\)(.*)(\[\/url\])/i", "\\2", $str);
  //QQ号码UBB
  $str = preg_replace("/\(*)\[\/qq\]/i", "", $str);
  

  $str = preg_replace("/(\)(.*)(\[\/b\])/", "\\2", $str);
  return $str;
  }
  

  if($_POST['sub']){
  echo get_ubb($_POST);
  }
  

  

  ?>
  
  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
页: [1]
查看完整版本: php创建属于自己的UBB代码