esiason14 Posted March 30, 2007 Share Posted March 30, 2007 I have a table that has a whole bunch of <tr>. For each one below I want to match the bolded text. <tr class="bg2" align="right" height="17" valign="middle"><td align="left">DATE</td><td align="left"><a href="/whatever/MATCH THESE NUMBERS">text< /a></td><td align="left">text</td><td align="left">more text</td><td align="left">more text</td><td align="left">MATCH THIS TEXT</td></tr> the numbers to be matched will be like this 3424532 the matched text can have special characters Once the matches are found...I'm going to have to run an update query for each..ie. UPDATE table set text=MATCH THIS TEXT where id=MATCH THESE NUMBERS; any help with the regex would be appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
Wildbug Posted March 30, 2007 Share Posted March 30, 2007 <?php $text = '<tr class="bg2" align="right" height="17" valign="middle"><td align="left">DATE</td><td align="left"> <a href="/whatever/4321100">text< /a></td><td align="left">text</td><td align="left">more text</td> <td align="left">more text</td><td align="left">MATCH THIS TEXT</td></tr>'; preg_match('/<tr.*?<a href=".*?(\d+)"(?:.*?<td align="left">){4}(.*?)<\/td><\/tr>/',$text,$matches); print_r($matches); ?> That regex works. $matches[1] contains "4321100" and $matches[2] contains "MATCH THIS TEXT". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.