473,378 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to read string from multiple rows in a textfile?

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
1 2770
pbmods
5,821 Expert 4TB
Heya, Boss.

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

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

Similar topics

5
by: deko | last post by:
I have a text file ("eighty.txt") that looks like this: 83|84|85|86 I can read the file into an array like this: $numbers= file("eighty.txt"); But how do I key the array? I'd like to use...
3
by: Elaksomfan | last post by:
Hi, I am having trouble importing data from an excel spreadsheet into MS SQL Server 2000 using DTS Wizard. The DTS import process is successfull, no errors, but only 50 rows of approx. 1500 rows...
2
by: Tim Bücker | last post by:
Hello. Is there a way to read a specified line in a textfile? Something like TextReader.ReadTextLine(4); It seems very odd to use reader.ReadLine(); reader.ReadLine(); reader.ReadLine();...
12
by: James Norton-Jones | last post by:
Hi, Am I trying to hold the data of a DataGrid in a label so that when the form is reposted the DataGrid can be repopulated. The problem I am having is that I don't understand how to get the...
4
by: Rich | last post by:
I understand that the stringbuilder object can create a string of text much more quickly/efficiently than a string object. I am just checking - if I have a textfile with say 1000 rows of data -...
9
by: Justme | last post by:
Novice programmer needs help with using fgets to read and ignore the first two lines of a file. I've gone thru the previous posting regarding fgets, but none of them seems to help my situation. I...
6
by: Alexandra | last post by:
Hi, I have a folder with hundreds of text files. Each text file contains a row with a date. I want to rename the text file with the date contained in this text file. Example: Suppose I have 2...
0
by: Snoze | last post by:
Hello, I'm trying to make an application with C# that writes and reads some lines of a text file, but I want to read one specific line and save the text in a string variable. And the inverse...
6
by: Per Juul Larsen | last post by:
Hi. My Textfile looks like this Variable 1 Variable 2 Variable 3 Variable 4 On opening the application it will read the textfile, and assign each line of variable to at textfield in VB and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.