ainoy31 Posted April 21, 2009 Share Posted April 21, 2009 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 More sharing options...
ainoy31 Posted April 21, 2009 Author Share Posted April 21, 2009 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. Link to comment https://forums.phpfreaks.com/topic/154985-solved-extract-data-from-a-text-file/#findComment-815201 Share on other sites More sharing options...
AE117 Posted April 21, 2009 Share Posted April 21, 2009 He solved it Link to comment https://forums.phpfreaks.com/topic/154985-solved-extract-data-from-a-text-file/#findComment-815206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.