Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7684517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:02:39+00:00 2026-05-31T19:02:39+00:00

I have text files containing structured data (it is a proprietary format and not

  • 0

I have text files containing structured data (it is a proprietary format and not something simple or common like CSV). I’m trying to put this data into a database. The text files are as large as 50GB so it’s impossible for me to read the entire file into memory, extract it into an array, then process it into the database.

The text files are structured in such a way that data on a particular “item” (a specific id in the database) can have multiple lines (new lines) of information in the text file. Items in the text file always start with a line that begins with ’01’ and can have an infinite number of additional lines (all one after the other), that will all start with 02 or 03 … up to 08. A new item begins when a new line starts with 01.

01some_data_about_the_first_item
02some_more_data_about_the_first_item
05more_data_about_the_first_item
01the_first_line_of_the_second_item

I’d like to use PHP to process this data.

How can I load a piece of this text file into memory where I can analyze it, get all the lines for an item, and then process it? Is there a way to load all lines up to the next line that starts with 01, process that data, then begin the next scan of the text file at the end of the last scan?

Processing the data once I’ve loaded pieces of it into memory is not the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:02:40+00:00Added an answer on May 31, 2026 at 7:02 pm

    Sure. Since you tagged the question with csv, I’ll assume you have a CSV file. In that case, fgetcsv is a good function to use, which get one line from the file at a time. Using that you can get as many lines as you need for one record, then process it, then continue with the next one. Rough mockup:

    $fh = fopen('file.csv', 'r');
    $record = array();
    
    do {
        $line = fgetcsv($fh);
    
        if ($line && $line[0] != '01') {
            // any line that does not start with 01 is part of the current record,
            // adjust condition as necessary
            $record[] = $line;
        } else if ($record) {
            /* put current $record into database */
    
            // start next record
            $record = array($line);
        }
    } while ($line);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files (f1 and f2) containing some text (or binary data). How
I have a text file containing the data in following format 12345 Abdt3 hy45d
I have a hierarchy of directories containing many text files. I would like to
I have a simple text file containing some CSV with the following structure: @Parent1_Field1,
I have a large number of text files (1000+) each containing an article from
I have a plain text file looking like this: some text containing line breaks
In a project we have text files looking like this: mv A, R3 mv
I have a directory with 260+ text files containing scoring information. I want to
I have some text files containing lines as follow : 07JAN01 , -0.247297942769082E+07, -0.467133797284279E+07,
I have 75+ different text files containing some lines of dialogue spoken by characters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.