...

View Full Version : preg_match_all pattern question #2



JustinMs66
07-12-2007, 10:12 PM
i really do not understand this.
this should be extremely simple yet it is not working...

i have this text:


$text = '
<td>
<%test1%>
<%test2%>
</td>

<td>
<%test3%>
<%test4%>
<%test5%>
</td>
';

and i want to split it into two arrays. both the contents of the insides of the <td></td>.

patterns i have tried:

$pattern = "/<td>(.*)<\/td>/";
$pattern = "/\<td\>(.*)\<\/td\>/";

and then:

preg_match_all($pattern,$text,$return);
var_dump($return);

and that will always return an empty array... i dont understand why.

_Aerospace_Eng_
07-12-2007, 10:21 PM
Try this for your pattern.

$pattern = "/<td.*?>.*?<\/td>/xmsi";
That will catch td cells that also have ids or classes on them.

gamer12
11-01-2009, 10:56 PM
I am getting stuck with similar problem. Say if I have many table rows like the followings

<tr title="abc"><td>...</td></tr>
<tr title="def"><td>...</td></tr>
<tr title="def"><td>...</td></tr>

How can I extract on those tr with title = "abc"?

Thanks for any help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum