Hello friends!

There is a very difficult task, in my opinion:

  1. There is a file (.txt)
  2. In the file line they contain the same type of information.
  3. The data types are ordered, i.e. follow each other in line
  4. In different lines, some data types are sometimes missing (skipped), and in other lines there is, the sequence of these data is observed in each of the lines.

Task:
It is necessary to construct a script that: Place the data types in columns and the results will be recorded in the MySql database.

  • 2
    Since the information does not have a rigid structure, try to parse the incoming information with regular expressions. - VladD
  • @ cheh1, what columns are in your database? - ReinRaus
  • @ReinRaus, the columns are: | Area | Object | Address | Area | Floors | Material | Description | Price | Description2 | Phone | ... friends, please show at least approximately - how to parse the information with regular expressions? - cheh1
  • @ cheh1, too complicated then parsing and ungrateful, I pass. I can tell Friedl's book on regulars to read. I can help how to select the entire address, description, price, telephone. - ReinRaus
  • 2
    @ cheh1, and the data reaches you in this form, or is it stored somehow differently? In the sense that maybe they can be prepared for further processing more correctly? - Deonis


2 answers 2

You need to familiarize yourself with the file_get_contents () function. If the data of each line is separated by some specific character, then you need to get acquainted with the function explode () . For the task, as you described it, this should be enough.

And about the "payment for labor" - so this is for freelancing, but not on this forum.

  • Thanks I will try! - cheh1
  • @ cheh1, what is there to try? ) // read the file $ content = file_get_contents ('file.txt'); // split by rows $ rows = $ explode ("\ r \ n", $ content); // if, for example, your data is separated by a semicolon, // then the next step is $ data_arr = array (); $ i = 0; foreach ($ rows as $ line) {$ data_arr [$ i ++] = explode (';', $ line); } // Finally, we have a two-dimensional array with all the data echo '<pre>'; print_r ($ data_arr); echo '</ pre>'; - Deonis
  • It’s better to be regular, the data is not homogeneous - ReinRaus
  • @ReinRaus, maybe, but I have the impression that the CS file is in CS style or similar to it with delimiters. - Deonis
  • @deonis TS in the first paragraph gave a link to the sample file, I also did not immediately notice :) - ReinRaus

There is a ready-made free software for such things, so as not to reinvent the wheel. I myself often drive data from excel to mysql and back through dbForge studio and mysqlConnector