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 Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted November 30, 2007 Author Share Posted November 30, 2007 Much thanks for the help.... Quote Link to comment 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; } } 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.