Может быть sscanf также может делать то, что вам нужно:
<?php
// in my example I loaded the data in an array line by line
$lines = file('sscanf_data.txt');
foreach($lines as $line) {
$data = array();
// define the format of the input string, assign the
// extracted data to an associative array
sscanf($line, "%s %s %s %s %[^.]",
$data['col_1'],
$data['col_2'],
$data['col_3'],
$data['col_4'],
$data['col_5']);
// dump array contents
print_r($data);
}
Вывод:
Array
(
[col_1] => AS
[col_2] => AF
[col_3] => AFG
[col_4] => 004
[col_5] => Afghanistan, Islamic Republic of
)
...
Хорошо, что если вы храните данные вВ ассоциативном массиве у вас уже есть пары полей-значений для вставки их в БД.