Jump to content

matching text/numbers in table


esiason14

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/44962-matching-textnumbers-in-table/
Share on other sites

<?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".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.