class csv
{
public $quotes='"';
public $delimiter=",";
function split($str)
{
$entered_quotes=false;
$ind=0;
$res='';
$coll='';
$len=strlen($str);
for($k=0;$k<$len;$k++)
{
if(($str[$k]==$this->delimiter)&($entered_quotes==false))
{
$res[$ind]=$coll;
$ind++;
$coll='';
continue;
};
if(($str[$k]==$this->quotes)&($entered_quotes==false))
{
$entered_quotes=true;
continue;
};
if(($str[$k]==$this->quotes)&($entered_quotes==true))
{
if($k==($len-1))
{
$res[$ind]=$coll;
$ind++;
return $res;
};
if(($k<($len-1))&($str[$k+1]==$this->quotes))
{
$coll.=$str[$k];
$k++;
continue;
};
$entered_quotes=false;
continue;
};
$coll.=$str{$k};
};
$res[$ind]=$coll;
return $res;
}
function join($arr)
{
$res="";
foreach($arr as $e)
{
if($res!=="")$res.=$this->delimiter;
if(strstr($e,$this->delimiter)!==false || strstr($e,$this->quotes)!==false)
$ne=preg_replace('/'.preg_quote($this->quotes).'/',$this->quotes.$this->quotes,$e);
if(isset($ne))$res.=$this->delimiter.$ne.$this->delimiter;
else $res.=$e;
}
return $res;
}
}
$fd=fopen($file_name,'r');
$csv=new csv;
while($str=fgets($fd))
{
$str_utf8=iconv("cp1251","utf-8",$str);
$values=$csv->split(trim($str));
// собираем и выполняем запрос
}
fclose($fd);
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.