Skip to content

Instantly share code, notes, and snippets.

@demoriz
Last active November 11, 2016 14:12
Show Gist options
  • Save demoriz/b3aa769533554119cb304fe8b79c6dde to your computer and use it in GitHub Desktop.
Save demoriz/b3aa769533554119cb304fe8b79c6dde to your computer and use it in GitHub Desktop.
bitrix template 'csv export'
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/classes/general/csv_data.php';
$strFilePath = $_SERVER['DOCUMENT_ROOT'] . '/upload/catalog.csv';
$obCsvFile = new CCSVData('R', false);
$obCsvFile->LoadFile($strFilePath);
$obCsvFile->SetDelimiter(';');
$arCatalog = array();
$arKeys = array();
$i = 0;
while ($arFields = $obCsvFile->Fetch()) {
if ($i == 0) {
$arKeys = $arFields;
$i++;
continue;
}
$arItem = array_flip($arKeys);
$j = 0;
foreach ($arItem as $strKey => $strValue) {
$arItem[$strKey] = $arFields[$j];
$j++;
}
$arCatalog[] = $arItem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment