Jump to content

[SOLVED] Need help on regex for customer information table


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
}

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.