Jump to content

[SOLVED] Screen Scrape


ainoy31

Recommended Posts

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

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

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
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.