Jump to content

[SOLVED] Extract Data from a text file


ainoy31

Recommended Posts

Here is my text file data:

 

1 Email [email protected],[email protected]

2 Email [email protected],[email protected]

3 Email [email protected]

1 Text [email protected],[email protected]

2 Text [email protected]

3 Text [email protected]

 

What I am looking for here is a pattern of "1 Text" and i need the phone numbers following it.

 

I have tried using this:

$myFile = "contactList.txt"; 
$handle = fopen($myFile, 'r'); 
while (!feof($handle)) 
{ 
$data = fgets($handle); 
if(eregi("1 Text", $data, $regs))
{
	print_r($regs); 
}
} 
fclose($handle); 

 

This just prints out array([0]=>1 Text).

 

Thanks.  AM

Link to comment
https://forums.phpfreaks.com/topic/154985-solved-extract-data-from-a-text-file/
Share on other sites

I figured it out.  Here is my solution:

 

$myFile = "contactList.txt";

$handle = fopen($myFile, 'r');

while (!feof($handle))

{

$data = fgets($handle);

$res = explode(" ", $data);

if( ($res[0] == 1) && $res[1] == 'Text')

{

$text = $res[2];

}

}

fclose($handle);

 

Thanks.

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.