Your IP : 3.139.80.212


Current Path : /home/bitrix/ext_www/vela.ballu.in.ua/php/
Upload File :
Current File : /home/bitrix/ext_www/vela.ballu.in.ua/php/import_cities.php

<?
header('Content-type: text/html; charset=windows-1251');
// setlocale(LC_ALL, 'ru_RU.UTF-8');
setlocale(LC_ALL, 'ru_RU.cp1251');
 
$file_name = 'flame_agents.csv';

$handle = fopen('php://memory', 'w+');
fwrite($handle, iconv('CP1251', 'CP1251', file_get_contents($file_name)));
rewind($handle);
while (($row = fgetcsv($handle, 1000, ';')) !== false){ 
	$parsed[] = $row;
}	
fclose($handle);
unset( $parsed[0] );


$arCity = array();
$arCities2 = array();
$i = 0;
$cityWordSec	= 1;
$cityWordCur	= '';
$countryHtml	= "var cities = {";

$k = 1;							
foreach($parsed as $city){
	if( !in_array($city[1], $arCity) ){
		$arCity[] = $city[1];
		$cityWordCur = mb_substr($city[1],0,1, 'CP1251');
		$cityWordCur = mb_strtoupper($cityWordCur, 'CP1251'); 
		$arCities2[$cityWordCur.$k] = $city[1];
		$k++;
	}	
}	
ksort($arCities2);
					
foreach( $arCities2 as $city ){
	$cityWordCur = mb_substr($city,0,1, 'CP1251');
	$cityWordCur = mb_strtoupper($cityWordCur, 'CP1251');

	if( $cityWordSec != $cityWordCur ){
		if( $cityWordSec != 1 ){
			$countryHtml .= "},";
		}
			$countryHtml .= "'".$cityWordCur."':{";
		$cityWordSec = $cityWordCur;
	}
	$countryHtml .= $i.":'".$city."',"; 
	$i++;
} 

$countryHtml .= '}};';

$fp = fopen(realpath ( '../js/' )."/cities.js", "w+"); 
$test = fwrite($fp, $countryHtml); 
fclose($fp);

if ($test) echo 'Данные в файл успешно занесены.';
else echo 'Ошибка при записи в файл.';


?>