mlav
mlav

Reputation: 24

How to remove whitespace between a <td> tag until the string?

I have a string

<td>    Some text</td><td>  July 3, 2013</td>

I want to remove the leading spaces so the resulting string looks like

<td>Some text</td><td>July 3, 2013</td>

I am playing around with preg_replace, but can't seem to figure out the proper syntax.

preg_replace('/<td>\s+/', '<td>', $strip2); **<-doesn't work**

Upvotes: 0

Views: 225

Answers (2)

mlav
mlav

Reputation: 24

Finally found the piece of code i needed to clean up my string

preg_replace('/[^(\x20-\x7F)]*/', '', $strip2);

Upvotes: -1

user4035
user4035

Reputation: 23749

Your regexp works perfectly:

<?php
$str = "<td>    Some text</td><td>  July 3, 2013</td>";
$str = preg_replace('/<td>\s+/', '<td>', $str);
print $str;

prints:

<td>Some text</td><td>July 3, 2013</td>

Upvotes: 2

Related Questions