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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

        )

 

)

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.