2014-06-11 21 views
1

我需要一個正則表達式,它將處理在文本編輯器中輸入的文本的格式。格式化HTML數據在客戶端使用jQuery/javascript

見這個網站

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt;line-height: 
normal;mso-pagination:none;mso-layout-grid-align:none;text-autospace:none;text-align:center;"><b><span style="font- size:14.0pt;font-family:&quot;Times-Roman&quot;,&quot;serif&quot;;mso-bidi-font-family: 
Times-Roman;color:#1B1E20">-- Michael Hirst</span></b><span style="font-size: 
14.0pt;font-family:&quot;Times-Roman&quot;,&quot;serif&quot;;mso-bidi-font-family:Times-Roman; 
color:#1B1E20">, creator, writer, and executive producer,&nbsp;Vikings</span><o:p></o:p></p> 

預期輸出:

<p style="text-align:center;"><span>--Michael Hirst</span></b><span>creator, writer, and executive producer,Vikings</span> 

我需要刪除類從HTML屬性。和我需要的內聯樣式除了只有文本對齊。 格式化這個後,我需要在PHP僅像我們做,除非一些標籤使用strip_tags的

strip_tags($html,"<b><h2><h3><h4><strong><div><p><br><ul><li><ol><blockquote>") 

這將是這樣做的正則表達式。我是這個正則表達式的新手!

回答

0

不要嘗試使用正則表達式解析html。有一個搜索 - 有很多例子,爲什麼不。由於您已爲問題與jQuery你可以使用這樣的事情作爲一個起點:

var $html = $('.MsoNormal + span').html(); 
$('p').css('text-align','center').append($html); 

DEMO here

+0

查看數據從文本編輯器來了。而且它總是不能在那裏存在。可以有任何格式。我只想格式化它。正如我在我的問題中提到的那樣。這是關於格式化HTML。 –

+0

@Creator如果HTML數據只是在文本編輯器中如何使用JavaScript或jQuery幫助解決問題? – garyh

+0

當用戶發佈它。我可以抓住他的輸入並在客戶端格式化並傳遞到服務器端。 @garyh –

相關問題