Last active
November 11, 2016 14:12
-
-
Save demoriz/b3aa769533554119cb304fe8b79c6dde to your computer and use it in GitHub Desktop.
bitrix template 'csv export'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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