Jump to content

[SOLVED] Need help on regex for customer information table


ian2k01

Recommended Posts

Hello,

 

I am trying to extract data from a cURL result into array and then insert into database. But need some hints on the regex for information extraction here:

...
<TD colspan="12"><img border="0" width="100%" height="1" src="./images/mdot.jpg"></TD>
</TR>
<TR height="25" bgcolor="#ffffff">
<TD></TD><TD align="left" class="bodytext">CLIENT_ID</TD><TD align="left" class="bodytext">TRANSACTION_ID_A</TD><TD align="left"><a class="hyperlink" href="javascript:DetailedTxn('CLIENT_ID', 'TRANSACTION_ID_B', 'ID')">TRANSACTION_ID_B</a></TD><TD align="right" class="bodytext">ID</TD><TD align="left" class="bodytext"><img border="0" width="10" height="1" src="./images/spacer.gif">CUSTOMER_NAME</TD><TD align="right" class="bodytext">AMOUNT</TD><TD align="right" class="bodytext">000</TD><TD align="right" class="bodytext">DATE</TD><TD align="right" class="bodytext"></TD><TD align="right" class="bodytext"><img border="0" width="2" height="1" src="./images/spacer.gif"></TD><TD width="1%"></TD>
</TR>
<TR height="25" bgcolor="#fceed8"> ...

 

The bgcolor="#ffffff" are odd rows and #fceed8 are even rows.

 

There is more than one row/record, and I'm not sure how to set each row's data into variables :(

 

Please help. Thank you!

This is only going to really be accurate if the only tr's on the page that have those 2 colors are the rows...

preg_match_all('~<tr[^>]*bgcolor\s?=\s?"#f(?:ceed8|fffff)"[^>]*>(.*?)</tr>~is',$string,$trMatches);
foreach ($trMatches[1] as $tr) {
  preg_match_all('~<td[^>]*>(.*?)</td>~is',$tr,$tdMatches);
  echo "<pre>"; print_r($tdMatches[1]); // example of where the data is at
  // put your db insert code here based off $tdMatches[1] array
}

 

Thanks so much Crayon Violent, it works just the way I wanted. :)

 

This is only going to really be accurate if the only tr's on the page that have those 2 colors are the rows...

preg_match_all('~<tr[^>]*bgcolor\s?=\s?"#f(?:ceed8|fffff)"[^>]*>(.*?)</tr>~is',$string,$trMatches);
foreach ($trMatches[1] as $tr) {
  preg_match_all('~<td[^>]*>(.*?)</td>~is',$tr,$tdMatches);
  echo "<pre>"; print_r($tdMatches[1]); // example of where the data is at
  // put your db insert code here based off $tdMatches[1] array
}

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.