A
A
abubekovdd2016-07-27 10:12:49
1C-Bitrix
abubekovdd, 2016-07-27 10:12:49

Parsing csv with a tab delimiter does not work - why?

require_once ($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/csv_data.php");
        $csvFile = new CCSVData('R', true);
        $csvFile->LoadFile($_SERVER["DOCUMENT_ROOT"] . '/upload/min.csv');//Файл
        $csvFile->SetDelimiter('\t'); //разделитель
        $bFirstHeaderTmp = $csvFile->GetFirstHeader();  //Заголовок
while ($arRes = $csvFile->Fetch()) { //Перебор CSV файла по полям
$arRes = $GLOBALS["APPLICATION"]->ConvertCharsetArray($arRes, "WINDOWS-1251", SITE_CHARSET);
            echo '<pre>';
            print_r($arRes);
            echo '</pre>';
}

Actually, this code will give the following result for one of the fields:
Array
(
    [0] => TRANSMASTER UNIVERSAL	45100I	Труба гофрированная универсальная 45X100	ШТУКА	1		336,9	4
)

That is, it turns out that the tabulation between the data is not recognized, since the expected result should be the following for one of the positions:
Array
(
[0]=>TRANSMASTER UNIVERSAL
[1]=>45230I
[2]=>Universal corrugated pipe 45X230
[3] =>STUKA
[4]=>1
[5]=>616,83
[6]=>8
)
If you save this file with any editor with a delimiter for example ',' - and change the delimiter in the code, then everything will work as it should. If the source file is again saved with a tab delimiter and changes are made to the code, then again the code does not work correctly.
Actually what's the catch?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-07-27
@abubekovdd

echo 'dfsdf \t dfsdfsd';
Try to display this and everything will become clear, if it becomes not clear, then you just entered 2 characters, not a tab character. Need double quotes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question