Answer the question
In order to leave comments, you need to log in
Why does fputcsv wrap strings in quotes?
The script collects data from different .xls files into an array, which is then immediately uploaded to CSV.
There are 2 types of files, both .XLS, but the structure is slightly different: in one, the lines are combined, so you have to mess around with them; besides, all the same, one of these lines stores several necessary data at once, well at least separated by the "|" symbol.
One way or another, the same array is obtained from both types of files: Article, manufacturer, price, quantity.
Examples of arrays, from two different files:
Array
(
[1] => Array
(
[sku] => KR0867M
[maker] => KRAUF
[name] => Модуль в сборе с бензонасосом
[quantity] => 1
[price] => 2508
)
[2] => Array
(
[sku] => SMD030764
[maker] => CHERY
[name] => Прокладка помпы
[quantity] => 1
[price] => 75
)
)
Array
(
[1] => Array
(
[sku] => 2300235K01J
[maker] => GREAT WALL
[name] => ПОДШИПНИК РОЛИКОВЫЙ ШЕСТЕРНИ БЛОКИРОВКИ ПЕРЕДНЕГО МОСТА HOVER - 2300235-K01
[quantity] => 1
[price] => 117.08
)
[2] => Array
(
[sku] => 2310012K01
[maker] => GREAT WALL
[name] => ШЕСТЕРНЯ БЛОКИРОВКИ ПЕРЕДНЕГО МОСТА HOVER
[quantity] => 1
[price] => 1266.19
)
)
$filename = explode(".", $file);
$output = fopen('csv/'.$filename[0].'.csv', 'w');
fputs($output, chr(0xEF) . chr(0xBB) . chr(0xBF)); // BOM
foreach ($row as $key)
{
fputcsv($output, $key, ';');
}
KR0867M;KRAUF;"Модуль в сборе с бензонасосом";1;2508
SMD030764;CHERY;"Прокладка помпы";1;75
" 2300235K01J ";"GREAT WALL ";" ПОДШИПНИК РОЛИКОВЫЙ ШЕСТЕРНИ БЛОКИРОВКИ ПЕРЕДНЕГО МОСТА HOVER - 2300235-K01";1;117.08
" 2310012K01 ";"GREAT WALL ";" ШЕСТЕРНЯ БЛОКИРОВКИ ПЕРЕДНЕГО МОСТА HOVER";1;1266.19
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question