ainoy31 Posted October 17, 2007 Share Posted October 17, 2007 Hello- I need help with scraping data from the screen. Here is what the data looks like: Status: DELIVERED 10/17/07. I can get the DELIVERED word out with no problem. Also, I need to get the date out as well. Here is my code: if(stristr($line, 'Status:')) { $status_line = $line_number; } . . . if(isset($status_line) and $status_line + 1 == $line_number) { if(stristr($line, 'Delivered')) { $delivered = true; $status = 'Delivered'; } else { $delivered = false; $status = trim(strip_tags($line)); $deliv_date = null; } I am stuck on it going pass the DELIVERED to get me date out. Hope this is clear enough. Much appreciation. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 <? $str = "Status: DELIVERED 10/17/07."; $pattern = "/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2})/"; $matches = array(); preg_match ($pattern, $str, $matches); print_r($matches); ?> output is: Array ( [0] => 10/17/07 [1] => 10 [2] => 17 [3] => 07 ) Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted October 17, 2007 Author Share Posted October 17, 2007 Thanks for the reply. It is almost working. Here is what is going on now. The date on the screen is 10/11/07. $pattern = "/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2})/"; preg_match($pattern, $line, $matches); print_r($matches); $date = trim( strip_tags( $matches[1] ) ); $date = substr( $date, 0, 6 ) . '20' . substr( $date, 6, 2 ); $deliv_date = date("Y-m-d", strtotime( $date ) ); $status = 'Delivered'; $delivered = true; The print out is Array ( [0] => 10/11/07 [1] => 10 [2] => 11 [3] => 07 ). I am trying to convert to the y-m-d format. When I echo $deliv_date, I get 2007-10-17 instead of 2007-10-11. Trying to figure out why it is adding 6 to the day. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 assuming there are no dates in the past, nor beyond 2099... $pattern = "/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2})/"; preg_match($pattern, $line, $matches); $date_string = "20".$matches[3]."-".$matches[1]."-".$matches[2]; but if they are, i guess i'd shortcut to: $deliv_date = date("Y-m-d", strtotime( $matches[0] ) ); Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted October 17, 2007 Author Share Posted October 17, 2007 Much appreciation.... That fixed the issue. 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.