ainoy31 Posted November 13, 2007 Share Posted November 13, 2007 Hello- Here is the layout of the data I need to get on the screen. <table width="100%" border="0" cellpadding="5" cellspacing="0" class="table th" style="border:10px #016801 solid;"> <tr> <th width="41%" bgcolor="#319a00" style="border:none;"> <div align="left">Current Status </div></th> <th width="59%" bgcolor="#319a00" style="border:none;"> <div align="right">Pro Number <span>I894451293</span> </div></th> </tr> <td bgcolor="#fcf920" colspan="2"><span class="current-status">This shipment was delivered on time on 11/02/07 AT 12:57PM- EST</span></td> </table> I am needing to get the date out. Here is what I have tried. $line_number = 1; $deliv_line = -4; foreach(explode("\n",$data) as $line) { if(stristr($line, ''<span class="current-status">")) { $deliv_line = $line_number; $pattern = "/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2})/"; preg_match($pattern,$line,$matches); print_r($matches); $deliv_date = date("Y-m-d", strtotime( $matches[0] ) ); }//end of if ++$line_number; } Much appreciation on any suggestion. Thanks. AM Link to comment https://forums.phpfreaks.com/topic/77201-solved-screen-scrap/ Share on other sites More sharing options...
GingerRobot Posted November 13, 2007 Share Posted November 13, 2007 I think you're probably making this more complicated than necessary. Is there actually another date on that page? If not, this would suffice: <?php $str = '<table width="100%" border="0" cellpadding="5" cellspacing="0" class="table th" style="border:10px #016801 solid;"> <tr> <th width="41%" bgcolor="#319a00" style="border:none;"> <div align="left">Current Status </div></th> <th width="59%" bgcolor="#319a00" style="border:none;"> <div align="right">Pro Number <span>I894451293</span> </div></th> </tr> <td bgcolor="#fcf920" colspan="2"><span class="current-status">This shipment was delivered on time on 11/02/07 AT 12:57PM- EST</span></td> </table>'; preg_match('|[0-9]{2}/[0-9]{2}/[0-9]{2}|',$str,$matches); print_r($matches); ?> Edit: If there is another date, then use: <?php $str = '<table width="100%" border="0" cellpadding="5" cellspacing="0" class="table th" style="border:10px #016801 solid;"> <tr> <th width="41%" bgcolor="#319a00" style="border:none;"> <div align="left">Current Status </div></th> <th width="59%" bgcolor="#319a00" style="border:none;"> <div align="right">Pro Number <span>I894451293</span> </div></th> </tr> <td bgcolor="#fcf920" colspan="2"><span class="current-status">This shipment was delivered on time on 11/02/07 AT 12:57PM- EST</span></td> </table>'; preg_match('|<span class="current-status">.*([0-9]{2}/[0-9]{2}/[0-9]{2})|',$str,$matches); $date = $matches[1]; echo $date; ?> Link to comment https://forums.phpfreaks.com/topic/77201-solved-screen-scrap/#findComment-390862 Share on other sites More sharing options...
ainoy31 Posted November 13, 2007 Author Share Posted November 13, 2007 Figured it out. I had to do strip the HTML tags off such as $data = strip_tags($data); and then $data = strip_tags($data); $line_number = 1; $deliv_line = -4; foreach(explode("\n",$data) as $line) { if(stristr($line, 'This shipment')) { $pattern = "/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2})/"; preg_match($pattern,$line,$matches); print_r($matches); $deliv_date = date("Y-m-d", strtotime( $matches[0] ) ); $status = 'Delivered'; $delivered = true; }//end of if Link to comment https://forums.phpfreaks.com/topic/77201-solved-screen-scrap/#findComment-390865 Share on other sites More sharing options...
ainoy31 Posted November 13, 2007 Author Share Posted November 13, 2007 Yes there is another date which is the Pickup Date. I was able to retreive that. I just had a hard time with the Delivery Date. Thanks. AM Link to comment https://forums.phpfreaks.com/topic/77201-solved-screen-scrap/#findComment-390866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.