ainoy31 Posted April 21, 2009 Share Posted April 21, 2009 Here is my text file data: 1 Email nick@yahoo.com,ainoy1@yahoo.com 2 Email jb@yahoo.com,ainoy1@yahoo.com 3 Email nick@yahoo.com 1 Text 4232121321@cingularme.com,8162321321@cingularme.com 2 Text 8162321321@cingularme.com 3 Text 2341232132@cingularme.com 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 Quote 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. Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.