首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视
设为首页
加入收藏
联系我们
热门关键字: .net应用  操作系统  Dreamweaver  WinRAR  网络推广
高级搜索
您当前的位置: 主页>编程相关>正则表达式>正则表达式实现Html转换UBB程序代码
正则表达式实现Html转换UBB程序代码
来源: 发布时间:2007-11-09 发布人: 浏览: 人次   字体: [ ]  

<html>
<head>
<title>Html转换程序</title>
<SCRIPT language="JavaScript1.2">
function HtmlToUBB(str) {
 str = str.replace(/\r/g,"");
 str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,"");
 str = str.replace(/<script[^>]*?>([\w\W]*?)<\/script>/ig,"");
 str = str.replace(/<a[^>]+href="([^"]+)"[^>]*>(.*?)<\/a>/ig,"\n[url=$1]$2[/url]\n");
 str = str.replace(/<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>/ig,"\n[color=$1]$2[/color]\n");
 str = str.replace(/<img[^>]+src="([^"]+)"[^>]*>/ig,"\n[img]$1[/img]\n");
 str = str.replace(/<([\/]?)b>/ig,"[$1b]");
 str = str.replace(/<([\/]?)strong>/ig,"[$1b]");
 str = str.replace(/<([\/]?)u>/ig,"[$1u]");
 str = str.replace(/<([\/]?)i>/ig,"[$1i]");
 str = str.replace(/ /g," ");
 str = str.replace(/&/g,"&");
 str = str.replace(/"/g,"\"");
 str = str.replace(/</g,"<");
 str = str.replace(/>/g,">");
 str = str.replace(/<br>/ig,"\n");
 str = str.replace(/<[^>]*?>/g,"");
 str = str.replace(/\[url=([^\]]+)\]\n(\[img\]\1\[\/img\])\n\[\/url\]/g,"$2");
 str = str.replace(/\n+/g,"\n");
 return str;
}
function trans(){
 var str = "";
 str = document.getElementById('edit').contentWindow.document.body.innerHTML;
 if (str.length == 0) {
  alert("无转换内容!请使用 Ctrl+V 把内容复制到下面的编辑框内");
  return
 }
 document.getElementById('ReCode').value=HtmlToUBB(str);
 document.getElementById('insert').disabled=false
}
function doHtmlinsert() {
 if (document.getElementById('ReCode').value=="") {alert("你没有进行代码转换,无法插入.");return}
 opener.AddText(document.getElementById('ReCode').value)
 window.close()
}
function clearCode(){
 document.getElementById('ReCode').value="";
}
function Start() {
  document.getElementById('edit').contentWindow.document.designMode = "on";
  try {
    document.getElementById('edit').contentWindow.document.execCommand("undo", false, null);
  }  catch (e) {
    alert("你的Mozilla浏览器不支持在线RichEditor");
  }
}
function ViewSource(Source){
  var Html;
  if (Source){
 document.getElementById('sCode').value = document.getElementById('edit').contentWindow.document.body.innerHTML;
 document.getElementById('edit').style.display="none";
 document.getElementById('sCode').style.display="";
 document.getElementById('tip').innerText="修改粘贴后的网页源代码 >>";
 document.getElementById('tranButton').disabled="disabled"
  }
  else{
 document.getElementById('edit').contentWindow.document.body.innerHTML = document.getElementById('sCode').value;
   document.getElementById('edit').style.display="";
 document.getElementById('sCode').style.display="none";
    document.getElementById('edit').contentWindow.document.designMode = "on";
  document.getElementById('tip').innerText="请使用 Ctrl+V 把内容复制到这里 >>";
 document.getElementById('tranButton').disabled=""
}
}
</SCRIPT>
<style>
body{background:#688ABD;margin:2px;}
label{color:#fff;}
th{font-size:14px;font-family:verdana,宋体;font-weight:bold;color:fc6;text-align:left}
#sCode{width:400;height:150px;border:1px solid #1F2F47;margin-top:0px !important;margin-top:-1px;margin-bottom:0px !important;margin-bottom:-1px;}
#ReCode{width:400;height:150px;border:1px solid #1F2F47;font-size:12px;}
#edit{width:398;height:148px;border:1px solid #1F2F47;background:#fff;font-size:12px}
.input{
 border-top:1px solid #fff;
 border-right:1px solid #003;
 border-bottom:1px solid #003;
 border-left:1px solid #fff;
 background:#F4F7FB;
}
.tip{
 color:#ffc;
 font-weight:bold;
 font-size:12px;
 font-family:宋体;
}
</style>
</head>
<body onload="Start()" style="">
<table border="0" align="center">
 <tr>
  <th style="">Html转换UBB程序</th>
 </tr>
 <tr>
  <td style="font-size:12px;">
   <label for="Source"><input type="checkbox" id="Source" onclick="ViewSource(this.checked)">查看源代码 </label>
         <input id="tranButton" type="button" value="转 换" onclick="trans()" class="input">
         <input type="button" value="清 除" onclick="clearCode()" class="input">
         <input id="insert" type="button" value="插 入" onClick="doHtmlinsert()" disabled class="input">
         </td>
 </tr>
 <tr>
  <td class="tip">
         <span id="tip">请使用 Ctrl+V 把内容复制到这里 >></span></td>
 </tr>
 <tr>
  <td>
         <textarea id="sCode" style="display:none"></textarea>
         <iframe id="edit"src="about:blank" border="0" frameborder="0"></iframe>
  </td>
 </tr>
 <tr>
  <td class="tip">
         转换输出代码 >></td>
 </tr>
 <tr>
  <td>
         <textarea id="ReCode" readonly="readonly"></textarea>
        </td>
 </tr>
</table>
</body>
</html>


相 关 文 章   发布商链接
·用正则表达式验证ip地址和身份证代码...
·正则表达式提取或校验网页脚本里的Ja...
·获取图片地址的正则表达式
·正则表达式30分钟快速入门教程
·编程开发中常用的javascript正则表达...
·解释正则表达式中的全部符号
·论坛E-mail验证的正则表达式升级了
·利用正则表达式去掉html代码
·正则表达式实现将首字单词转成大写
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·正则表达式30分钟快速入门教...
·获取图片地址的正则表达式
·正则表达式提取或校验网页脚...
·用正则表达式验证ip地址和身...
·正则表达式实现将首字单词转...
·利用正则表达式去掉html代码
·论坛E-mail验证的正则表达式...
·解释正则表达式中的全部符号
热 门 文 章
·用正则表达式验证ip地址和身...
·获取图片地址的正则表达式
·利用正则表达式去掉html代码
·编程开发中常用的javascript...
·正则表达式实现将首字单词转...
·解释正则表达式中的全部符号
·论坛E-mail验证的正则表达式...
·正则表达式提取或校验网页脚...
·正则表达式30分钟快速入门教...
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .