Jump to content

[SOLVED] Another Screen Scrap ?


ainoy31

Recommended Posts

Hello-

 

Here is the layout of the data I need to get, which are the two dates.

 

<td align="center">11/10/07</td>

<td>JMFRCA</td>

<td style="white-space:nowrap:">Canton</td>

<td align="center">MA</td>

<td>45451515</td>

<td align="center">11/17/07</td>

 

Here is what I have tried:

 

foreach(explode("\n", $data) as $line)

{

if(stristr($line, $pro))

{

$pickup_line = $line_number;

$pattern = '|<td align="center">.*([0-9]{2})\/([0-9]{2})\/([0-9]{2})|';

preg_match($pattern, $line, $matches);

}

 

If I do a print_r($matches), the array does not have the dates separated.  I have tried to strip the HTML tags off but that becomes even more messy. Much appreciation on suggestions. Thank you.  AM

Link to comment
https://forums.phpfreaks.com/topic/77387-solved-another-screen-scrap/
Share on other sites

<pre>
<?php
$data = <<<DATA
	<td align="center">11/10/07</td>
	<td>JMFRCA</td>
	<td style="white-space:nowrap:">Canton</td>
	<td align="center">MA</td>
	<td>45451515</td>
	<td align="center">11/17/07</td>
DATA;
preg_match_all('%(?<=<td align="center">)\d{2}/\d{2}/\d{2}%', $data, $matches);
print_r($matches);
?>
</pre>

$line = <td align="center">11/10/07</td><td>JMFRCA</td><td style="white-space:nowrap:">Canton</td><td align="center">MA</td><td>45451515</td><td align="center">11/17/07</td>

 

I was able to resolve my issue.  Solution:

 

Since I know that the first date is the pickup date and the last date is the delivery date, I wrote my script base on that.

 

foreach(explode("\n", $data) as $line)

{

if(stristr($line, $pro))

{

$pattern = "/([0-9]{2})\/([0-9]{2})\/([0-9]{2})/";

preg_match($pattern, $line, $matches);

$pu_date = date("Y-m-d", strtotime( $matches[0] ) );

}//end of if

if(stristr($line, $pro))

{

preg_match('|<td align="center">.*(\d{2}/\d{2}/\d{2})|', $line, $matches);

$deliv_date = date("Y-m-d", strtotime( $matches[1] ) );

$status = 'Delivered';

$delivered = true;

if($matches[1] == '')

{

$delivered = false;

$status = 'In Route';

$deliv_date = null;

}

}

 

Thanks for the help.

It does work:

 

<pre>
<?php
$data = <<<DATA
<td align="center">11/10/07</td><td>JMFRCA</td><td style="white-space:nowrap:">Canton</td><td align="center">MA</td><td>45451515</td><td align="center">11/17/07</td>
DATA;
preg_match_all('%(?<=<td align="center">)\d{2}/\d{2}/\d{2}%', $data, $matches);
print_r($matches);
?>
</pre>

 

Array

(

    [0] => Array

        (

            [0] => 11/10/07

            [1] => 11/17/07

        )

 

)

Archived

This topic is now archived and is closed to further replies.

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