2016-07-26 78 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的例子。