Jump to content

extract address, city, phone


Recommended Posts

hi to all,

i have a simple, just a simple concern.

how to extract address, city and phone in this txt file?

RL              ACCOUNTANTS WAREHOUSE                                                                                                        6070 MC*DONOUGH DR N*W                                 NORC                            770 326-6302V2 
RL              ACCOUN*TAX PROFESSIONAL                                                                                                                                                                                             770 447-1244V2
RL              ACCOUNTAX SERVICE                                                                                                            6000 LIVE OAK PKWY N*W                                 NORC                            678 206-0361V2

 

 

can i use preg_match()?

any advice?

 

thanks

???

Link to comment
Share on other sites

try

<?php
$a = 'RL              ACCOUNTANTS WAREHOUSE                                                                                                        6070 MC*DONOUGH DR N*W                                 NORC                            770 326-6302V2 
RL              ACCOUN*TAX PROFESSIONAL                                                                                                                                                                                             770 447-1244V2
RL              ACCOUNTAX SERVICE                                                                                                            6000 LIVE OAK PKWY N*W                                 NORC                            678 206-0361V2';
$a = explode("\n",$a);
$final = array();
foreach ($a as $row => $line){
$data[0] = trim(substr($line,  0, 16));
$data[1] = trim(substr($line, 16,125));
$data[2] = trim(substr($line,141, 55));
$data[3] = trim(substr($line,196, 32));
$data[4] = trim(substr($line,228, 12));
$data[5] = trim(substr($line,240,  2));
$final[] = $data;
}
print_r($final);
?>

Link to comment
Share on other sites

thanks!,

i comeup with this script from your script

$a = file('gin002.txt');
/*$a = 'RL              ACCOUNTANTS WAREHOUSE                                                                                                        6070 MC*DONOUGH DR N*W                                 NORC                            770 326-6302V2 
RL              ACCOUN*TAX PROFESSIONAL                                                                                                                                                                                             770 447-1244V2
RL              ACCOUNTAX SERVICE                                                                                                            6000 LIVE OAK PKWY N*W                                 NORC                            678 206-0361V2';*/

foreach ($a as $row => $line){
//$data[0] = trim(substr($line,  0, 16))."<br />";
//$data[1] = trim(substr($line, 16,125))."<br />";
$data[2] = trim(substr($line,141, 55))."<br />";
$data[3] = trim(substr($line,196, 32))."<br />";
$data[4] = trim(substr($line,228, 14))."<br />";
//$data[5] = trim(substr($line,240,  2))."<br />";
$final[] = $data;
}
//$a = explode("\n",$a);
print_r($final)."<br />";

 

and the result is this.

Array ( [0] => Array ( [2] => 
[3] => 
[4] => 
) [1] => Array ( [2] => 
[3] => SNVL
[4] => 770 979-2966
) [2] => Array ( [2] => 6070 MC*DONOUGH DR N*W
[3] => NORC
[4] => 770 326-6302
) [3] => Array ( [2] => 
[3] => 
[4] => 770 447-1244
) [4] => Array ( [2] => 6000 LIVE OAK PKWY N*W
[3] => NORC
[4] => 678 206-0361
) [5] => Array ( [2] => 4995-D FRIENDSHIP RD
[3] => BUFORD
[4] => 770 614-6440
) [6] => Array ( [2] => 2624 GLADSTONE TERRACE
[3] => WDSTK
[4] => 770 846-7799
) [7] => Array ( [2] => 4455 COMMERCE DR N*E
[3] => BUF
[4] => 770 271-0051
) [8] => Array ( [2] => 2265 SUGARBIRCH DR S*W
and so on.......

 

how can i remove

Array ( [0] => Array ( [2] => 

in the result?

 

Link to comment
Share on other sites

<?php
$a = file('gin002.txt');
/*
$a = 'RL    
RL              ACCOUNTANTS WAREHOUSE                                                                                                        6070 MC*DONOUGH DR N*W                                 NORC                            770 326-6302V2 
RL              ACCOUN*TAX PROFESSIONAL                                                                                                                                                                                             770 447-1244V2
RL              ACCOUNTAX SERVICE                                                                                                            6000 LIVE OAK PKWY N*W                                 NORC                            678 206-0361V2';
$a = explode("\n",$a);
*/
foreach ($a as $row => $line){
//$data[0] = trim(substr($line,  0, 16))."<br />";
//$data[1] = trim(substr($line, 16,125))."<br />";
$data[2] = trim(substr($line,141, 55))."<br />";
$data[3] = trim(substr($line,196, 32))."<br />";
$data[4] = trim(substr($line,228, 14))."<br />";
//$data[5] = trim(substr($line,240,  2))."<br />";
if ($data[2]!= "<br />" or $data[3] != "<br />" or $data[4] != "<br />") $final[] = $data;
}
//$a = explode("\n",$a);
print_r($final)."<br />";
?>

Link to comment
Share on other sites

great! it extracted only the address city and phone!

and it only use foreach, trim and substr functions.

can the

Array ( [0] => Array (" 

not be displayed?can it be removed? undisplay the "array" word...

 

i comeup with this script

$a = file('gin002.txt');
/*
$a = 'RL    
RL              ACCOUNTANTS WAREHOUSE                                                                                                        6070 MC*DONOUGH DR N*W                                 NORC                            770 326-6302V2 
RL              ACCOUN*TAX PROFESSIONAL                                                                                                                                                                                             770 447-1244V2
RL              ACCOUNTAX SERVICE                                                                                                            6000 LIVE OAK PKWY N*W                                 NORC                            678 206-0361V2';
$a = explode("\n",$a);
*/

foreach ($a as $row => $line){
//$data[0] = trim(substr($line,  0, 16))."<br />";
//$data[1] = trim(substr($line, 16,125))."<br />";
$data[2] = trim(substr($line,141, 55))."<br />";
$data[3] = trim(substr($line,196, 32))."<br />";
$data[4] = trim(substr($line,228, 14))."<br />";
//$data[5] = trim(substr($line,240,  2))."<br />";
if ($data[2]!= "<br />" or $data[3] != "<br />" or $data[4] != "<br />") $final[] = $data;
}
//$a = explode("\n",$a);
for($i = 1;$i <=10; $i++)
{
$final[$i];

echo $data[2];
echo $data[3];
echo $data[4];

}

//print_r($final)."<br />";

?>

but the result is only 1 record and it keeps on repeating.

3000 LANGFORD RD N*W
NORCROSS
770 447-5283
3000 LANGFORD RD N*W
NORCROSS
770 447-5283
3000 LANGFORD RD N*W
NORCROSS
770 447-5283
3000 LANGFORD RD N*W
NORCROSS
770 447-5283
3000 LANGFORD RD N*W
NORCROSS
770 447-5283
3000 LANGFORD RD N*W
NORCROSS
770 447-5283
3000 LANGFORD RD N*W
NORCROSS
770 447-5283
3000 LANGFORD RD N*W
NORCROSS
770 447-5283
3000 LANGFORD RD N*W
NORCROSS
770 447-5283
3000 LANGFORD RD N*W
NORCROSS
770 447-5283

 

By the way the $i is the number of words.

 

 

thanks

 

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.