简单的Html转换UBB的程序_正则表达式

这个功能主要是让 UBB 转贴的时候方便点. 

1.自动识别图片,超链接,字体颜色,和字体加粗,倾斜,下划线的HTML代码,并且转换为UBB代码.
2.兼容 IE 和 Mozilla多种浏览器
<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 把内容复制到下面的编辑框内");
}
document.getElementById('ReCode').value=HtmlToUBB(str);
}

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"></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>

时间: 2024-08-29 11:55:08

简单的Html转换UBB的程序_正则表达式的相关文章

简单的Html转换UBB的程序

这个功能主要是让 UBB 转贴的时候方便点.  1.自动识别图片,超链接,字体颜色,和字体加粗,倾斜,下划线的HTML代码,并且转换为UBB代码.2.兼容 IE 和 Mozilla多种浏览器<html> <head> <title>Html转换程序</title> <SCRIPT language="JavaScript1.2"> function HtmlToUBB(str) { str = str.replace(/r/g

Html转换UBB程序_正则表达式

Html转换UBB程序 查看源代码 请使用 Ctrl+V 把内容复制到这里 >> 转换输出代码 >>

正则表达式简单的检查输入email是否合法程序_正则表达式

function chkEmail(email) on error resume next dim i,l,pos1,pos2 chkEmail=true if isnull(email) then chkEmail=false:exit function  pos1= instr(email,"@") pos2=instrRev(email,".") if not(pos1>0) or not (pos2>0) or pos1>pos2 then

论坛UBB代码 推荐_正则表达式

复制代码 代码如下: <%dim param,smiles  'param是UBB标签完全可用的标记 param=full 则完全可用,否则不支持一些占位大的标签 smiles是禁止笑脸转换function UBBCode(content)dim n,i'on error resume nextset re=new regexpre.IgnoreCase=truere.global=true re.pattern="\[code\](\r\n)?([\s\S]+?)\[\/code\]&q

[a] 1 [/a]转换为网址的UBB的正则_正则表达式

上面这个东东如何才能变成下面那个? 复制代码 代码如下: [a] 1 [/a] 2 [a]3[/a] 4 [/a] 5  [/a] 6 [a] 7 [/a]  [a] 8 [/a]  <a f="1"> 1 <a f="2"> 2 <a f="3">3</a> 4 </a> 5  </a> 6 <a f="7"> 7 </a>  &

Html转换UBB程序

<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)="[^

windows-电脑版的wap浏览器程序_编写

问题描述 电脑版的wap浏览器程序_编写 我是新注册CSDN的学生党一名,想请教下各位,,,我想编写一个wap浏览器,目前是 编程入门,然后想问下Windows编程里面有没有wap编程的API可用,还有能在哪里找到这方面的资料?我在MSDN逛了下完全就是睁眼瞎... 解决方案 最简单的就是拖一个webbrowser控件(mfc的doc/view里面叫chtmlview) 解决方案二: 你可以在代码资源里面搜索一下啊. 解决方案三: 给你个网址http://www.w3school.com.cn/

垃圾引用防治补丁以及发送引用修正补丁的自动安装程序_应用技巧

实在没辙,PJBlog 的垃圾引用防治补丁以及新日志发送失败的修正补丁发布后,天天都有因为修改错误而找上门询问的.为了简化大家的升级步骤,减少升级造成的错误.本人参考了部分前辈的程序后,做出了前面两个补丁的自动安装程序,代码替换,数据库升级都一步到位.恩恩.废话少讲,给下载,大家记得升级前要备份哈,尤其是数据库一定要备份一次. 虽然本程序在本人的本地环境里的全新 PJBlog 上测试成功,但不能排除装过其他插件的博客不会出现问题.如果您升级出现了差错请到:http://www.myyu.net/

php实现转换ubb代码的方法_php技巧

本文实例讲述了php实现转换ubb代码的方法.分享给大家供大家参考.具体如下: function ubb2html($content) { global $article; //是否自动识别 if ($article['isparseurl'] == "1") { $content = parseurl($content); } //自动识别结束 $content = eregi_replace(quotemeta("[b]"),quotemeta("&l