ian2k01 Posted May 28, 2009 Share Posted May 28, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/160049-solved-need-help-on-regex-for-customer-information-table/ Share on other sites More sharing options...
.josh Posted May 28, 2009 Share Posted May 28, 2009 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 } Quote Link to comment https://forums.phpfreaks.com/topic/160049-solved-need-help-on-regex-for-customer-information-table/#findComment-844402 Share on other sites More sharing options...
ian2k01 Posted May 28, 2009 Author Share Posted May 28, 2009 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 } Quote Link to comment https://forums.phpfreaks.com/topic/160049-solved-need-help-on-regex-for-customer-information-table/#findComment-844417 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.