ainoy31 Posted November 30, 2007 Share Posted November 30, 2007 Hello- Here is the data: <TR> <TD ALIGN="LEFT"> <SMALL><B>Pickup Date:</B> 11/14/2007</SMALL><BR><SMALL><B>Delivery Date:</B> 11/15/2007</SMALL><BR><SMALL><B>Delivery Status:</B> Delivered</SMALL><BR><SMALL><B>Delivery Time:</B> 11:29</SMALL><BR> <TD> </TR> I need to get the Delivery Status: out. Here is what I have tried: foreach(explode("\n", $data) as $line) { if(stristr($line, '<B>Delivery Status:</B>')) { preg_match('#(Delivery Status):.([^"]*?)#is', $data, $matches); print_r($matches); } } Any suggestion is much appreciated. AM Link to comment https://forums.phpfreaks.com/topic/79563-solved-screen-scrape/ Share on other sites More sharing options...
effigy Posted November 30, 2007 Share Posted November 30, 2007 <pre> <?php $data = <<<DATA <TR> <TD ALIGN="LEFT"> <SMALL><B>Pickup Date:</B> 11/14/2007</SMALL><BR><SMALL><B>Delivery Date:</B> 11/15/2007</SMALL><BR><SMALL><B>Delivery Status:</B> Delivered</SMALL><BR><SMALL><B>Delivery Time:</B> 11:29</SMALL><BR> <TD> </TR> DATA; preg_match('%(?<=Delivery Status:</B>)\s*([^<]+)%', $data, $matches); array_shift($matches); print_r($matches); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/79563-solved-screen-scrape/#findComment-402970 Share on other sites More sharing options...
ainoy31 Posted November 30, 2007 Author Share Posted November 30, 2007 Much thanks for the help.... Link to comment https://forums.phpfreaks.com/topic/79563-solved-screen-scrape/#findComment-402980 Share on other sites More sharing options...
ainoy31 Posted November 30, 2007 Author Share Posted November 30, 2007 Here is the solution: foreach(explode("\n", $data) as $line) { if(stristr($line, 'Pickup Date:')) { $pattern = "/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/"; preg_match($pattern, $line, $matches); $pu_date = date("Y-m-d", strtotime($matches[0])); } if(stristr($line, 'Delivery Date:')) { preg_match_all('#(Delivery Date):.*?(\d{2}/\d{2}/\d{4})#is', $data, $matches, PREG_SET_ORDER); $deliv_date = date("Y-m-d", strtotime($matches[0][2])); $status = 'Delivered'; $delivered = true; if($matches[0][2] == '') { preg_match('%(?<=Delivery Status:</B>)\s*([^<]+)%', $data, $matches); array_shift($matches); $status = $matches[0]; $delivered = false; $deliv_date = null; } } Link to comment https://forums.phpfreaks.com/topic/79563-solved-screen-scrape/#findComment-402982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.