P
P
pingo2016-09-13 16:20:41
PHP
pingo, 2016-09-13 16:20:41

How to parse a large text file in php?

There is a large, no.. very large file, approximately 1,800,000 * 150 lines.
The need arose to translate it from a text format into mysql for ease of access to information.
I haven't tried parsing it yet, but if it's translated into an array line by line, then .. it probably won't work.
as it should in pieces. what options are there, besides cutting the file into pieces (into a bunch of smaller files)?
and how to open it for editing, even FIG knows
what options there are, where to dig?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Philipp, 2016-09-13
@pingo

Use stream_get_line or fgets to read line by line. The fgets manual has a good example.
If the file is structured (eg CSV), then you can use LOAD DATA INFILE dev.mysql.com/doc/refman/5.7/en/load-data.html

M
Michael, 2016-09-13
@springimport

If I understand correctly and you have 1.8M lines, then you should try to make a large swap file and run everything on a local computer, especially since the process is one-time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question