Welcome to WebmasterWorld Guest from 54.196.214.35

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

string parsing

ideal way of parsing string from a text file

     
11:49 pm on Feb 4, 2004 (gmt 0)

Full Member

10+ Year Member

joined:May 9, 2002
posts:241
votes: 0


is there a fastest and most efficient way of parsing text from a file using php's built in function?

the file contains data delimited by some character like '&' and by new lines. i use the "file" function to convert the lines into array then use foreach to read each line then use "parse_str" to get the data i need.

anyone have a faster way of doing this or dealing with such? thanks.

6:41 pm on Feb 5, 2004 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


I don't usually use file. I usually read line by line and process that way. As with most parsing tasks, you have to be familiar with the type and amount of data to be sure that your method is the most efficient.

Most of my parsers are for various types of logs and the amount of data can be overwhelming. I never use file because the thought of loading 500K lines into an array always makes my servers cry a little. ;)

7:39 pm on Feb 5, 2004 (gmt 0)

Full Member

10+ Year Member

joined:May 9, 2002
posts:241
votes: 0


thanks for your insight. do you use fgetcsv? or other? please let me know so that I could personally try it and compare the speed. Thanks again.
9:15 pm on Feb 5, 2004 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


fgetcsv
fgets
fgetss
fread

it all depends on what type of data you are working with