By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,187 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,187 IT Pros & Developers. It's quick & easy.

how to read string from multiple rows in a textfile?

P: 45
i have textfile containing multiple rows.Each row containing same type of strings.now my problem is i can read only one row frequently but i can't read multiple rows.

so how can i solve this problem Is there anybody expart to help me?

Text to be read is:
Expand|Select|Wrap|Line Numbers
  1. 03/31/02 04:21PM   136 11 9564499-                       00:00'54            TR 
  2.  
  3.  03/31/02 04:22PM   202 10 8916116                        00:00'05               
  4.  
  5.  03/31/02 04:23PM   125 08 108                            00:00'32               
  6.  
  7.  
  8.  03/31/02 04:23PM   142 06 <I>                       0'00 00:00'31            TR 
  9.  
  10.  03/31/02 07:51AM       13 <I>                       0'05                     NA 
  11.  
  12.  03/31/02 04:22PM   202 10 9338340                        00:00'00               
  13.  
  14.  
my
trial code is:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. $file = fopen("rawdata.txt","r");
  5.  
  6. while(! feof($file))
  7.   {
  8.   //echo fgets($file). "<br />";
  9.   $first=trim($first.fgets($file));
  10.   //echo $first;
  11.   }
  12.     $first1= substr($first,0,8);
  13.     echo $first1." ";
  14.     //mysql_query("insert into test(name) values($first1)");
  15.   //echo $first1;
  16. /*$file1 = fopen("raw_da
  17.   {ta_31_03.txt","rb");  
  18.   while(! feof($file1))
  19.   //echo fgets($file). "<br />";
  20.   */
  21.   //$second=trim($second.fgets($file1));
  22.  
  23.  
  24.     $second1= substr($first,9,7);
  25.     echo $second1 ." ";
  26.  
  27.  
  28.     $third= substr($first,17,5);
  29.     echo $third ." ";
  30.  
  31.     $fourth= substr($first,23,2);
  32.     echo $fourth ." ";
  33.  
  34.     $fifth= substr($first,25,11);
  35.     echo $fifth ." ";
  36.     $sixth= substr($first,50,15);
  37.     echo $sixth ." ";
  38.     $seventh= substr($first,77,2);
  39.     echo $seventh ." ";
  40.  
  41.  
  42. fclose($file);
  43.  
  44. ?>
Oct 27 '07 #1
Share this Question
Share on Google+
1 Reply


pbmods
Expert 5K+
P: 5,821
Heya, Boss.

This looks like a job for Regular Expressions!.
Oct 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.