Jamess Moriarty
Jamess Moriarty

Reputation: 39

php preg replace with spaces and new line breaks

i have a text (in file with spaces and tabs)

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

  </tr>

and preg replace search

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

it's not my regular expression, but client say that it works before, after some research i'm found that is some problem with spaces or new line /n. If i trying find only one string it's work. I'm tying add /r/n nothing help. Maybe somebody can help me

Upvotes: 0

Views: 77

Answers (1)

Blue
Blue

Reputation: 22911

Just use \s+ when looking for any whitespace. It's the cheap and easy way out.

<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>

See this regex101 link for an example.

Upvotes: 1

Related Questions