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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.