If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Data From Certain Line In txt Files

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-08-04, 21:36
delMONT delMONT is offline
Registered User
 
Join Date: Nov 2004
Posts: 1
Data From Certain Line In txt Files

ok, i know how to show a certain line from a text file but say I had a text file like this:

bill | 23 | php
fred | 19 | cgi
frank | 20 | asp
brian | 33 | php
edward | 27 | php
james | 30 | asp

how would go about getting the data of lines 3 to 5? like this:

frank | 20 | asp
brian | 33 | php
edward | 27 | php

Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 11-09-04, 10:32
princes princes is offline
Registered User
 
Join Date: Oct 2004
Location: Germany
Posts: 10
I do not realy understand what your problem is, but i think this will help you:

PHP Code:
fscanf resource handlestring format [, string var1]) 
example:
PHP Code:
fscanf($stream,"%s | %s | %s",$name,$id,$what); 
but i do not know if this work ...

good luck ;P

//EDIT

here is a url
__________________
[/.. Höre alles, glaube wenig, sage nichts ..\]

Last edited by princes; 11-09-04 at 10:34. Reason: forgotten URL
Reply With Quote
  #3 (permalink)  
Old 11-24-04, 19:50
pebkac pebkac is offline
Registered User
 
Join Date: Jan 2004
Posts: 35
Smile Read into an Array

You should be able to read information by each line into an array. Remember an array starts with a '0'. Here is some code that I have used in the past to read each rows and then also split them out which may be what you want to do anyway.

// -- Variables --
$file_dir = "mydir"; // Directory Of Text File
$myfile = "myfile.txt"; // Text File
$filearray= file("$file_dir/$myfile"); // Opens File for Array Reading

// -- Splitting array per line by delmiter | in file
// -- Getting line 3 - 5 into array
// -- You may have to change the '3' at the end of the line to pertain
// to you depending on how you want to parse it.
list($row3_left,$row3_middle,$row3_right)= split("|",$filearray[2], 3);
list($row4_left,$row4_middle,$row4_right)= split("|",$filearray[3], 3);
list($row5_left,$row5_middle,$row5_right)= split("|",$filearray[4], 3);


Doing this will create a total of nine parsed out variables you can use.

I have not tested this with your information, but this should be close to what you need to use it for.

Hopfully this helps
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On