Skip to content

有害部落格同好會

2005/11/30 / Others

清除多餘html代碼

在搜尋CF問題時發現一篇有用的技巧: 清除從word粘貼過來多餘html代碼的ClearWord函數

轉貼自: CFDP 作者:子心 2005.11.29

我們在利用FckEditor編輯器的時候會有一個清除從Word粘貼過來的多餘html代碼的功能,它是利用JavaScript編寫的。有了這項功能以後,我們的網頁內容可以直接從Word拷貝粘貼而不用擔心內容裡會有一大堆多餘的東西佔據資料庫空間影響網頁執行的性能了。

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


function CleanWord(html)
{
html = REReplaceNocase(html,'s*< /o:p>','','all');
html = REReplaceNocase(html,'.*?< /o:p>',' ','all');
html = REReplaceNocase(html,'s*mso-[^:]+:[^;"]+;?','','all');
html = REReplaceNocase(html,'s*MARGIN: 0cm 0cm 0pts*;','','all');
html = REReplaceNocase(html,'s*MARGIN: 0cm 0cm 0pts*"','"','all');
html = REReplaceNocase(html,'s*TEXT-INDENT: 0cms*;','','all');
html = REReplaceNocase(html,'s*TEXT-INDENT: 0cms*"','"','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,']*>s* s*< /SPAN>',' ','all');
html = REReplaceNocase(html,']*>< /SPAN>','','all');
html = REReplaceNocase(html,'< (w[^>]*) lang=([^ |>]*)([^>]*)','< 1','all');
html = REReplaceNocase(html,'(.*?)< /SPAN>','1','all');
html = REReplaceNocase(html,'(.*?)< /FONT>','1','all');
html = REReplaceNocase(html,'< \??xml[^>]*>','','all');
html = REReplaceNocase(html,'< /?w+:[^>]*>','','all');
html = REReplaceNocase(html,'s*< /Hd>','','all');
html = REReplaceNocase(html,'

]*)>','
','all'); html = REReplaceNocase(html,'

]*)>','
','all'); html = REReplaceNocase(html,'

]*)>','
','all'); html = REReplaceNocase(html,'

]*)>','
','all'); html = REReplaceNocase(html,'
]*)>','
','all'); html = REReplaceNocase(html,'
]*)>','
','all'); html = REReplaceNocase(html,'< /Hd>','

','all'); html = REReplaceNocase(html,'< (U|I|STRIKE)> < /1>',' ','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>)','

','all'); return html; }

Post navigation

Previous Post:

製作載入圖片的效果

Next Post:

WINXP製作可還原檔

分類

  • 新奇有趣の搶先報導
    • Raspberry Pi
    • 手機相關
    • 推薦軟體
    • 新鮮有趣
    • 生活資訊
  • 想破腦袋の程式技巧
    • Oracle EBS
    • Database
    • Excel, VBA
    • php
    • JavaScript, VBScript
    • VS.NET
    • Others
    • Windows
    • SAP
  • 撩動心弦の短文小品
  • 聚沙成塔の理財守則
  • 不可不知の職場實錄
  • 剎那永恆の生活翦影

近期文章

  • 受保護的內容: 如何透過Personalize功能呼叫另一form來回傳值
  • Win10 / 8 / 7 無法安裝 SSD
  • 受保護的內容: 樹梅派+遠端連線
  • EBS R12 取得客戶的phone, email, URL資料
  • 受保護的內容: 管控Workflow Administrator Role

友站

  • Masaya396's 協奏曲
  • 老塗的咁仔店

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

Tag Cloud

你目前使用的瀏覽器不支援 HTML5 的 CANVAS 標籤。

  • excel
  • EBS 11.5.10
  • HTC
  • WinXP
  • CSS
  • Oracle DB
  • javascript
  • VBA
  • 管理
  • Oracle EBS
  • 感情
  • Win7
  • MySql
  • VB6
  • EBS 12.1.3
  • LDAP
  • SQL
  • php
  • VB.Net
  • SAP
© 2025 有害部落格同好會 - Powered by SimplyNews