![]() |
parsing a page line by line
hello,
i have a page which contains about 5000 lines. each line is in this format vocab n. definition how can i have php read the first word and place it into a tables column then the second word/char which is n and place that into another column and the last word into another column? |
PHP Code:
|
The only trouble with using
file is that you're loading the entire file into memory. Much better is to read the file line by line and do with it what you want.Here are two approaches using this line of thought. Plain old fopen/fgets PHP Code:
PHP Code:
|
I hadn't even considered the memory usage when I quickly typed that out.
I've never seen SplFileObject used before that is a nice class. Any idea why it hasn't made it into the official docs yet? |
| All times are GMT. The time now is 10:53 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0