Inserting lines from a txt into MySQL

Hi there!

I would love some help on a problem, as I’m a novice at PHP…

I want to open a .txt file (which I can do), but then I want to insert each line into a row of my database.

Also, each line has [number] (a number encased in square brackets) before the text, which I want to remove when it’s inserted.

Will anyone help me?

The general point of programming help forums is that you post code you have written, along with any question, error, or symptom you need help with for that code.

Does the [number] have any white-space before the text that you also want to remove? Are there any unique values in the data that can be used as an identifier in the database table? How big is the .txt file? How often will you perform this operation? If you perform this operation more than once, what do you want to do for duplicate data?

Hey @Messiah. One thing you can try is to use the function file, which will turn your .txt file into an array of strings, which you can iterate over and process individually.
Once you have a single line, processing it would mean:

  1. Remove the number encased in square brackets
  2. Insert the text into the database

Now, to give you more details I’d need to know the answer to some of the questions posted by @phdr
If you already have some code written, please post it here so we can take a look.

Another question.
How & why is the text file created?

@Mchojrin - Sorry for the delay. Been locked with limited computer access. I’ll take this and come back when I encounter the next problem.

Thanks, man!

To world peace.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service