2016-07-26 77 views
0

我有一個文本(在文件中有空格和製表符)PHP預浸空格替換和新的換行符

<tr> 
<th width="219" rowspan="2">dsf</th> 
<th width="60" rowspan="2">dsfsdf</th> 
<th width="135" colspan="2">dsfdsf</th> 

    </tr> 

和浸漬料代替搜索

"! <tr> 
    <th width=\"219\" rowspan=\"2\">dsf</th> 
    <th width=\"60\" rowspan=\"2\">dsfsdf</th> 
    <th width=\"135\" colspan=\"2\">dsfdsf</th> 
    </tr>!is", 

這不是我的正則表達式,但客戶端說它的工作之前,經過一些研究,我發現這是一些空間或新行/ n的問題。如果我試圖找到只有一個字符串它的工作。我正在添加/ r/n沒有任何幫助。 也許有人可以幫我

+0

不要在html上使用正則表達式。如果您試圖破壞html,請使用DOM解析器。 –

回答

1

只要使用\s+當查找任何空格。這是便宜和簡單的出路。

<tr>\s+<th width=\"219\" rowspan=\"2\">dsf</th>\s+<th width=\"60\" rowspan=\"2\">dsfsdf</th>\s+<th width=\"135\" colspan=\"2\">dsfdsf</th>\s+</tr> 

查看this regex101 link的例子。