ainoy31 Posted December 5, 2007 Share Posted December 5, 2007 Hello- I need help with getting data off the screen. Here is the data: <tr> <td class="text" width='90' align='right' bgcolor='#f5deb3'>Pickup Date:</td> <td class="text" width='90' bgcolor='#f5f5dc'><b>12/04/07</b></td> <td class="text" width='90' align='right' bgcolor='#f5deb3'>Del Date/Time:</td> <td class="text" width='90' bgcolor='#f5f5dc'><b>* in route *</b></td> </tr> I need to get the status of the Del Date/Time field out which is * in route * but it could be a date later on. Here is what I have tried. foreach(explode("\n",$data) as $line) { if(stristr($line, 'Del Date/Time:')) { preg_match('%(?<=Del Date/Time:</td>)\s*([^<]+)%', $data, $matches); print_r($matches); } } Much appreciation. Quote Link to comment Share on other sites More sharing options...
dsaba Posted December 8, 2007 Share Posted December 8, 2007 I need help with getting data Care to explain more specifically how we can help you? What is your problem and what is the output of $matches ? Posting this information would certainly help see where your problem is, of course you'll have to state what your problem is first. Quote Link to comment Share on other sites More sharing options...
jcd Posted December 9, 2007 Share Posted December 9, 2007 1: <tr> 2: <td class="text" width='90' align='right' bgcolor='#f5deb3'>Pickup Date:</td> 3: <td class="text" width='90' bgcolor='#f5f5dc'><b>12/04/07</b></td> 4: <td class="text" width='90' align='right' bgcolor='#f5deb3'>Del Date/Time:</td> 5: <td class="text" width='90' bgcolor='#f5f5dc'><b>* in route *</b></td> 6: </tr> foreach(explode("\n",$data) as $line) { if(stristr($line, 'Del Date/Time:')) { preg_match('%(?<=Del Date/Time:</td>)\s*([^<]+)%', $data, $matches); print_r($matches); } } Your IF condition (in bold above) will only be positive and come into play at line 4:. Since this is inside a foreach loop, line 4 is the only line that exists, therefore your preg_match will never find the *in route* which is on line 5. Quote Link to comment Share on other sites More sharing options...
dsaba Posted December 9, 2007 Share Posted December 9, 2007 <?php $str = <<<EOD <tr> <td class="text" width='90' align='right' bgcolor='#f5deb3'>Pickup Date:</td> <td class="text" width='90' bgcolor='#f5f5dc'>12/04/07</td> <td class="text" width='90' align='right' bgcolor='#f5deb3'>Del Date/Time:</td> <td class="text" width='90' bgcolor='#f5f5dc'>* in route *</td> </tr> EOD; $pat = '~Del Date/Time:\</td\> \<td class="text" width=\'90\' bgcolor=\'#f5f5dc\'\>((??!\</td\>).)+)\</td\>~s'; preg_match_all($pat, $str, $out); print_r($out); ?> this works as long as: Del Date/Time:</td> <td ^ end of del/date td tag and next td tag are seperated by 1 space you can change the pattern to suit however else it may be seperated, like with a line break, depending on your data, a good rule of thumb is just to remove all line breaks period from the haystack, and then search data, but it can be done without that as well using $ and ^ or s modifiers.. it really depends how static or not this data you are searching through is coming in.... so you must know details/specifics to make such a decision 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.