Is this the actual contents of your file?
*2001
7894900010015 150
7894900010020 300
7899400500465 050
7894643812312 100
*2002
7894900016156 035
7894881561861 011
7894860450002 001
*2003
7894868153183 335
7898456484411 200
*2004
7894868153001 355
7898456484002 211
IF SO, let's do this:
<?php
$file = file( "path/to/your/file",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES );
…which results in an array like so:
array(15) {
[0]=>
string(5) "*2001"
[1]=>
string(17) "7894900010015 150"
[2]=>
string(17) "7894900010020 300"
[3]=>
string(17) "7899400500465 050"
[4]=>
string(17) "7894643812312 100"
[5]=>
string(5) "*2002"
[6]=>
string(17) "7894900016156 035"
[7]=>
string(17) "7894881561861 011"
[8]=>
string(17) "7894860450002 001"
[9]=>
string(5) "*2003"
[10]=>
string(17) "7894868153183 335"
[11]=>
string(17) "7898456484411 200"
[12]=>
string(5) "*2004"
[13]=>
string(17) "7894868153001 355"
[14]=>
string(17) "7898456484002 211"
}
Then, we can parse it one line at a time:
<?php
foreach( $file as $line ){
// "*" indicates a new year
if( strpos( $line,"*" ) === 0 ){
$lote = substr( $line,1,4 );
}
// otherwise, assume it's an "ean qtd" string.
// note; this assumes that the first line in the file is a "year" line.
// if it's not, you'll end up with records that have empty years
// (as well as an "undefined variable" error).
else{
// this will fail if you ever have a line that is improperly formatted
// (e.g., no space / extra spaces).
list( $ean,$qtd ) = explode( " ",$line );
// put values into a set for SQL query
// this also assumes that all data in your file is SAFE.
// if not, you'll need to escape these values before now.
$values[] = "('$lote','$ean','$qtd')";
}
}
// combine all value-sets for SQL query
$SQL = "INSERT INTO your_table(lote,ean,qtd) VALUES\n ".implode( ",\n ",$values );
Which results in this SQL string:
INSERT INTO your_table(lote,ean,qtd) VALUES
('2001','7894900010015','150'),
('2001','7894900010020','300'),
('2001','7899400500465','050'),
('2001','7894643812312','100'),
('2002','7894900016156','035'),
('2002','7894881561861','011'),
('2002','7894860450002','001'),
('2003','7894868153183','335'),
('2003','7898456484411','200'),
('2004','7894868153001','355'),
('2004','7898456484002','211')