ainoy31 Posted November 14, 2007 Share Posted November 14, 2007 Hello- Here is the layout of the data I need to get, which are the two dates. <td align="center">11/10/07</td> <td>JMFRCA</td> <td style="white-space:nowrap:">Canton</td> <td align="center">MA</td> <td>45451515</td> <td align="center">11/17/07</td> Here is what I have tried: foreach(explode("\n", $data) as $line) { if(stristr($line, $pro)) { $pickup_line = $line_number; $pattern = '|<td align="center">.*([0-9]{2})\/([0-9]{2})\/([0-9]{2})|'; preg_match($pattern, $line, $matches); } If I do a print_r($matches), the array does not have the dates separated. I have tried to strip the HTML tags off but that becomes even more messy. Much appreciation on suggestions. Thank you. AM Quote Link to comment Share on other sites More sharing options...
effigy Posted November 14, 2007 Share Posted November 14, 2007 <pre> <?php $data = <<<DATA <td align="center">11/10/07</td> <td>JMFRCA</td> <td style="white-space:nowrap:">Canton</td> <td align="center">MA</td> <td>45451515</td> <td align="center">11/17/07</td> DATA; preg_match_all('%(?<=<td align="center">)\d{2}/\d{2}/\d{2}%', $data, $matches); print_r($matches); ?> </pre> Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted November 14, 2007 Author Share Posted November 14, 2007 Thanks for the reply. Took your suggestion and the array is empty. Quote Link to comment Share on other sites More sharing options...
effigy Posted November 14, 2007 Share Posted November 14, 2007 The example I posted returns data. How did you implement it? Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted November 14, 2007 Author Share Posted November 14, 2007 Instead of using $data in the preg_match_all(), I used the $line variable. Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted November 14, 2007 Author Share Posted November 14, 2007 Like this: preg_match_all('%(?<=<td align="center">)\d{2}/\d{2}/\d{2}%', $line, $matches); Quote Link to comment Share on other sites More sharing options...
effigy Posted November 15, 2007 Share Posted November 15, 2007 And what's in $line? Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted November 15, 2007 Author Share Posted November 15, 2007 $line = <td align="center">11/10/07</td><td>JMFRCA</td><td style="white-space:nowrap:">Canton</td><td align="center">MA</td><td>45451515</td><td align="center">11/17/07</td> I was able to resolve my issue. Solution: Since I know that the first date is the pickup date and the last date is the delivery date, I wrote my script base on that. foreach(explode("\n", $data) as $line) { if(stristr($line, $pro)) { $pattern = "/([0-9]{2})\/([0-9]{2})\/([0-9]{2})/"; preg_match($pattern, $line, $matches); $pu_date = date("Y-m-d", strtotime( $matches[0] ) ); }//end of if if(stristr($line, $pro)) { preg_match('|<td align="center">.*(\d{2}/\d{2}/\d{2})|', $line, $matches); $deliv_date = date("Y-m-d", strtotime( $matches[1] ) ); $status = 'Delivered'; $delivered = true; if($matches[1] == '') { $delivered = false; $status = 'In Route'; $deliv_date = null; } } Thanks for the help. Quote Link to comment Share on other sites More sharing options...
effigy Posted November 16, 2007 Share Posted November 16, 2007 It does work: <pre> <?php $data = <<<DATA <td align="center">11/10/07</td><td>JMFRCA</td><td style="white-space:nowrap:">Canton</td><td align="center">MA</td><td>45451515</td><td align="center">11/17/07</td> DATA; preg_match_all('%(?<=<td align="center">)\d{2}/\d{2}/\d{2}%', $data, $matches); print_r($matches); ?> </pre> Array ( [0] => Array ( [0] => 11/10/07 [1] => 11/17/07 ) ) Quote Link to comment 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.