IT学习者 | 文章大全 | 技术文档 | 桌面壁纸 | 实用查询 | 网络电台 | 成语 | 歇后语 | 网址 | 下载 | 周公解梦 | 生日密码 | 电视剧365 | Flash
 您现在的位置: IT学习者 >> 文章大全 >> 网页制作 >> HTML&CSS

清除從word粘貼過來多餘html代碼的ClearWord函數

【 来源:网络  更新时间:2006-2-13 | 字体:
我們在利用FckEditor編輯器的時候會有一個清除從Word粘貼過來的多餘html代碼的功能,它是利用javascript編寫的。有了這項功能以後,我們的網頁內容可以直接從Word拷貝粘貼而不用擔心內容裏會有一大堆多餘的東西佔據資料庫空間影響網頁執行的性能了。

那麼,我們參照了Fckeditor的javascript功能編寫了CFScript功能版本的ClearWord函數,利用該函數在頁面內容添加入庫時可以直接進行清除冗餘操作了。

<!--- 
/***********************************************************
* 頁面功能         : 清除從word粘貼過來多餘html代碼 
* 作者                : 子心(方曉恩) 
* 版本                : 1.0 
* 創建時間         : 2005-11-29 
* 作者主頁         : http://www.cfcodes.com 
* 聯繫郵箱         : chinavane@msn.com 
* Msn號碼          : chinavane@msn.com 
* Oicq號碼         : 13525442
* 歷史版本         : 

 * 參數                :[html] 帶有Word冗餘代碼的html內容 
***********************************************************/ 
--->
<cfscript>
    function CleanWord(html) 
    { 
        html = REReplaceNocase(html,'<o:p>\s*<\/o:p>','','all'); 
        html = REReplaceNocase(html,'<o:p>.*?<\/o:p>','&nbsp;','all'); 
        html = REReplaceNocase(html,'\s*mso-[^:]+:[^;"]+;?','','all'); 
        html = REReplaceNocase(html,'\s*MARGIN: 0cm 0cm 0pt\s*;','','all'); 
        html = REReplaceNocase(html,'\s*MARGIN: 0cm 0cm 0pt\s*"','\"','all'); 
        html = REReplaceNocase(html,'\s*TEXT-INDENT: 0cm\s*;','','all'); 
        html = REReplaceNocase(html,'\s*TEXT-INDENT: 0cm\s*"','\"','all'); 
        html = REReplaceNocase(html,'\s*TEXT-ALIGN: [^\s;]+;?"','\"','all'); 
        html = REReplaceNocase(html,'\s*PAGE-BREAK-BEFORE: [^\s;]+;?"','\"','all'); 
        html = REReplaceNocase(html,'\s*FONT-VARIANT: [^\s;]+;?"','\"','all'); 
        html = REReplaceNocase(html,'\s*tab-stops:[^;"]*;?','','all'); 
        html = REReplaceNocase(html,'\s*tab-stops:[^"]*','','all'); 
        html = REReplaceNocase(html,'\s*face="[^"]*"','','all'); 
        html = REReplaceNocase(html,'\s*face=[^ >]*','','all'); 
        html = REReplaceNocase(html,'\s*FONT-FAMILY:[^;"]*;?','','all'); 
        html = REReplaceNocase(html,'<(\w[^>]*) class=([^ |>]*)([^>]*)','<\1','all'); 
        html = REReplaceNocase(html,'<(\w[^>]*) style="([^\"]*)"([^>]*)','<\1','all'); 
        html = REReplaceNocase(html,'\s*style="\s*"','','all'); 
        html = REReplaceNocase(html,'<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>','&nbsp;','all'); 
        html = REReplaceNocase(html,'<SPAN\s*[^>]*><\/SPAN>','','all'); 
        html = REReplaceNocase(html,'<(\w[^>]*) lang=([^ |>]*)([^>]*)','<\1','all'); 
        html = REReplaceNocase(html,'<SPAN\s*>(.*?)<\/SPAN>','\1','all'); 
        html = REReplaceNocase(html,'<FONT\s*>(.*?)<\/FONT>','\1','all'); 
        html = REReplaceNocase(html,'<\\?\?xml[^>]*>','','all'); 
        html = REReplaceNocase(html,'<\/?\w+:[^>]*>','','all'); 
        html = REReplaceNocase(html,'<H\d>\s*<\/H\d>','','all');   
        html = REReplaceNocase(html,'<H1([^>]*)>','<div\1><b><font size="6">','all'); 
        html = REReplaceNocase(html,'<H2([^>]*)>','<div\1><b><font size="5">','all'); 
        html = REReplaceNocase(html,'<H3([^>]*)>','<div\1><b><font size="4">','all'); 
        html = REReplaceNocase(html,'<H4([^>]*)>','<div\1><b><font size="3">','all'); 
        html = REReplaceNocase(html,'<H5([^>]*)>','<div\1><b><font size="2">','all'); 
        html = REReplaceNocase(html,'<H6([^>]*)>','<div\1><b><font size="1">','all');            
        html = REReplaceNocase(html,'<\/H\d>','</font></b></div>','all'); 
        html = REReplaceNocase(html,'<(U|I|STRIKE)>&nbsp;<\/\1>','&nbsp;','all'); 
        html = REReplaceNocase(html,'<([^\s>]+)[^>]*>\s*<\/\1>','','all'); 
        html = REReplaceNocase(html,'<([^\s>]+)[^>]*>\s*<\/\1>','','all'); 
        html = REReplaceNocase(html,'<([^\s>]+)[^>]*>\s*<\/\1>','','all'); 
        html = REReplaceNocase(html,'(<P)([^>]*>.*?)(<\/P>)','<div\2</div>','all'); 
        return html; 
    }
</cfscript>
相 关 文 章
相 关 软 件
没有相关下载
逃生 放生 黄玫瑰 想太多 那滋味 擦肩而过 放手去爱 北京欢迎你 依然在一起 吻得太逼真 感动天感动地 坐上火车去拉萨 怎么会狠心伤害我
心碎 冲动 小太阳 别碰我 蒲公英 千山万水 改变自己 一定要爱你 等爱的玫瑰 陷入爱里面 北极星的眼泪 最后一次的温柔 亲爱的那不是爱情
光荣 火花 坏女人 日不落 樱花草 为你写诗 独家记忆 夏天的味道 寂寞才说爱 忘不掉的伤 爱上你是个错 第三者的第三者 地球人都知道我爱你
假如 相思 是非题 有缘人 舍不得 我的答铃 死而无憾 外滩十八号 越爱越难过 123木头人 和寂寞说分手 爱上你是我的错 爱情里没有谁对谁错
加入收藏留言建议自助友情链接普通友情链接站长的Blog
版权所有   COPYRIGHT 2002-2008 ★IT学习者★ ALL RIGHTS RESERVED.