2013-06-21 39 views
0

我想清理一個cms數據庫:所有的內容都有內聯樣式,我需要去掉它們。正則表達式模式不能在特定情況下工作

我有很多嵌套標記,所以我試圖用<h3>(我確定標題沒有嵌套)替換<span>標記,然後用HTMLPurifier清理其他標記。

我寫這符合<h3>更換<span>標籤:

$string = preg_replace('/<span style="line-height: 17pt; font-family: helvetica; color: rgb\(85, 85, 85\); font-size: 13pt; font-weight: bold;">(.*?)<\/span>/', '<h3>$1</h3>',$string); 

它可以在任何情況下exept此:

<span style="line-height: 17pt; font-family: helvetica; color: rgb(85, 85, 85); font-size: 13pt; font-weight: bold;">"Rischio obsolescenza" per i lettori Blu-ray</span> 

也許「的文字是問題

我該如何解決這個問題?

回答

1

不,引號不是問題,正則表達式在我的測試中確實匹配。你確定你的中間沒有換行符,因爲除非你使用/s修飾符,否則點不匹配它們。所以,請嘗試

$string = preg_replace('/<span style="line-height: 17pt; font-family: helvetica; color: rgb\(85, 85, 85\); font-size: 13pt; font-weight: bold;">(.*?)<\/span>/s', '<h3>$1</h3>',$string); 
相關問題