Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text file parsing question

Status
Not open for further replies.

intrex

IS-IT--Management
Apr 14, 2002
70
US
Hello,

I have only been working with php for about 2 hours now so bare with me if I type something stupid.

I am trying to open up a remote text file, parse the file, and output the parsed text as html. As of now I can open the file read characters into a buffer and then output them as html. My problem is with parsing the buffer to get to the text I want to output.

Should I read the entire file into an array? Then output the parts of the array I want to show? If so please post some type of example code.

Does php have functions to move through a file and choose which characters you want to put into an array?

Any help would be greatly appreciated.

Thanks for your time
 
I generally recommend not reading an entire file into memory. The exceptions are when the file is guaranteed to be small or when the file you have to process has information on one line modifying the interpretation of the information on another.

PHP has a function to arbitrarily move the file pointer through a file: fseek() (documented at
______________________________________________________________________
TANSTAAFL!
 
there is also the fgets() function which read n characters
until there is no \n. So, I use it like this :
while($line = fgets($file, 100000)){
....
}
But you must be sure that there is no line over 100000 characters :cLike that you read your file line after line....
@++
 
Thanks alot for the info. I am currently working on another project now so I don't have time to try and implement you guys suggestions, but I will soon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top