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

  • SEARCH
  • Home
  • 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 3674948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:54:58+00:00 2026-05-19T02:54:58+00:00

I have a set of textfiles containing personal data. I want to use a

  • 0

I have a set of textfiles containing personal data. I want to use a script to run through them and write them to a mysql database.
What I have done so far is to read the text file into a string, explode the string at ” ” and then run through the array to find the required information. There are a couple of problems with that though, so maybe someone knows a better solution alltogether.

The base text file looks like this:

Name: Marius
Address 1: Street
Address 2: Town
Address 3: Country
etc

The problem in this is that I have no way of knowing how long the ‘value’ of i.e. Street is. Could be just the ‘Somestreet’ or ‘Some Street’ or ‘Some Street 1337’. This goes for pretty much every field.

Is there maybe a method to turn that text into an array, where for every item the string ending with “:” is used as the key and every following item without ending “:” is considered the value?

  • 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-19T02:54:59+00:00Added an answer on May 19, 2026 at 2:54 am

    As Adam hints in the comments: If there is no tab, cr/lf or similar delimiter, there is not enough information in your string to parse the data by.

    If there is only a limited set of keys, you can provide this set as additional information.
    Since you want to insert the data into a mysql table, I assume that the keys are limited and unique.
    With an array of these key strings, your parser algorithm would work this way:

    1 explode the string at ":"
    2 loop through the resulting array, where you should find a structure like this:
        [some or no value][space or other delimiter][known key]
    2.1 remember the key from the previous loop (empty as default)
    2.2 since the keys should be unique, loop through the array of known keys
    2.2.1 if a key matches the current string structure from the right, you can 
        strip this key off the right side of the string, trim the string and you
        have the current value
    2.2.2 if you found a value, put both into the result array: 
        $arr[previous key] = [current value]
    

    This should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to load set of questions to MYSQL database table.But the table format
I have the following script that loops through textfiles an replaces the letter a
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have set of flat files (114 files) each file is named with database
I have a scheduled task set up to run Scan.aspx every 3 minutes in
I have two text files, and a PHP script intended to delete them. My
I have set up a cron task and I want to save the output
I have a set of data stored in text files, which I have now
I have a large set of text files (tab delimited data) I need to
I have set the eclipse java formatter to wrap lines that exceed 120 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.