How to read txt lines and insert into Database with PHP

Asked

Viewed 46 times

1

I need to take the value of each row and each column to insert into the database, but there are results that the Observations field are in two lines and is actually the continuation of the previous row. I’m not getting it in the continuation of the previous line.

Link to the TXT

The result I need is this:

<table>
<thead>
   <tr>
       <th>IDENT ANV</th>
       <th>TIPO</th>
       <th>ADEP</th>
       <th>EOBT</th>
       <th>VEL</th>
       <th>FL</th>
       <th>ROTA</th>
       <th>DEST</th>
       <th>EET</th>
       <th>OBS</th>
    </tr>
    </thead>
    <tbody>
    <tr>
       <td>AZU2400</td>
       <td>E190</td>
       <td>SBGR</td>
       <td>11:25</td>
       <td>N396</td>
       <td>290</td>
       <td>DCT DORLU UZ37 VUREP DCT</td>
       <td>SBRJ</td>
       <td>00:40</td>
       <td>EQPT/SDFGHIRWY PBN/A1B1D1O1S2</td>
    </tr>
    </tbody>
</table>

  • Boot, please an example of a comment in two lines. It stands in two <td>different s, even, or only have a line break within a single <td>?

1 answer

0

Your data source is very irregular.

First of all, it is not using line-breaking delimiters ( n r), which makes it impossible to read standardized, the text is all indented by spaces, and as the field observations sometimes appear randomly with 10 or 6 digits, it is very difficult to extract data.

What I recommend is that you first standardize the data source and then do the necessary work.

In case the nearest regular expression I arrived was :

/\d{6}.+(\w{3,4}/\w{8,10}) {1,4}/g

But I reiterate that without break lines and without standardization, regular expression will not serve.

To test use the http://regexr.com/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.