html转ubb php,window_简单的Html转换UBB的程序,这个功能主要是让 UBB 转贴的 - phpStudy...

简单的Html转换UBB的程序

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

1.自动识别图片,超链接,字体颜色,和字体加粗,倾斜,下划线的HTML代码,并且转换为UBB代码.

2.兼容 IE 和 Mozilla多种浏览器

Html转换程序

function HtmlToUBB(str) {

str = str.replace(/\r/g,"");

str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,"");

str = str.replace(/

str = str.replace(/]+href="([^"]+)"[^>]*>(.*?)<\/a>/ig,"\n[url=$1]$2[/url]\n");

str = str.replace(/]+color=([^ >]+)[^>]*>(.*?)<\/font>/ig,"\n[color=$1]$2[/color]\n");

str = str.replace(/]+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(/,"<");

str = str.replace(/>/g,">");

str = str.replace(/
/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=""

}

}

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:宋体;

}

Html转换UBB程序

查看源代码

请使用 Ctrl+V 把内容复制到这里 >>

转换输出代码 >>

相关阅读:

建立动态的WML站点(二)

JSP初学者必须掌握的语法点

Cont()与Where().Count()有时性能差别如此之大!

织梦dedecms sitemap路径修改方法

获取table中的rowIndex和cellIndex

ext form 表单提交数据的方法小结

PHP在网站开发中的一些优势

隐性调用php程序的方法

网页中包含文件小结

ASP教程:自己写的数据库操作类

Asp.net用户管理API的应用

php调用远程url的六种方法

分析:2007年一季度Linux市场增长31%

AJAXCALL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值