Jump to content

[SOLVED] Screen Scrap


ainoy31

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.